import SocketIO
let manager = SocketManager(socketURL: URL(string: "http://localhost:8080")!, config: [.log(true), .compress])
let socket = manager.defaultSocketsocket.on(clientEvent: .connect) {data, ack in
print("socket connected")
}
socket.connect()
I migrate from swift 3 to swift 4.
I switched to the latest version, I created the SocketManager, but I can not connect to the socket.
Have you checked the logs? Make sure the manager isn't being released.
@nuclearace I edit my code like this:
let manager = SocketManager(socketURL: myURL, config: [SocketIOClientOption.log(true), SocketIOClientOption.reconnects(true), SocketIOClientOption.sessionDelegate(self), SocketIOClientOption.compress, SocketIOClientOption.extraHeaders(["Cookie" : cookie, "Cache-control": "no-cache"])])
socket = manager.defaultSocket
socket.on("connect") { data, ack in
print("Connesso")
}
socket.on("error") { data, ack in
}
socket.connect()
the log does not appear
Are you running this inside of an app or just a main.swift? If you're not running inside of an app you need to start the main runloop.
The previous version ( I used v12.1.3) worked properly, with this SocketManager no longer.
Well, if logs aren't being printed then something is going very wrong...
Is this syntax correct?
var socket:SocketIOClient! = nil
let manager = SocketManager(socketURL: myURL, config: [SocketIOClientOption.log(true), SocketIOClientOption.reconnects(true), SocketIOClientOption.sessionDelegate(self), SocketIOClientOption.compress, SocketIOClientOption.extraHeaders(["Cookie" : cookie, "Cache-control": "no-cache"])])
socket = manager.defaultSocket
socket.on("connect") { data, ack in
print("Connesso")
}
socket.on("error") { data, ack in
}
socket.connect()
Manager needs to be a property or a global. If it's not, then the manager will be released and it won't work. The actual socket object doesn't need to be stored; you can always access it from defaultSocket or the socket(forNamespace:) method.
ok seems to work again. thanks and close
Most helpful comment
Manager needs to be a property or a global. If it's not, then the manager will be released and it won't work. The actual socket object doesn't need to be stored; you can always access it from
defaultSocketor thesocket(forNamespace:)method.