To make a connection to v4.5.2 socket.IO in a node.js server, I updated swift client from version 15.2.0 to version 16.0.1
The new v4.5.2 socket.IO works perfectly well with the java and Android client, but there the swift client always use long-polling, and not possible to move to websocket transport after the first polling.
The transport is always set to polling. In order to fix it, I set .forceWebsockets(true), but it is not possible to make an establish a connection after it. The transport should be set to webcocket
Here is the logs
2022-09-16 18:05:40.275708+0200 app-name[1597:395115] LOG OnAckCallback: OnAckCallback for 0 being released
2022-09-16 18:05:54.825999+0200 app-name[1597:395444] LOG SocketEnginePolling: Got polling response
2022-09-16 18:05:54.826233+0200 app-name[1597:395444] LOG SocketEnginePolling: Got poll message: 2
2022-09-16 18:05:54.826520+0200 app-name[1597:395444] LOG SocketEngine: Got message: 2
2022-09-16 18:05:54.826844+0200 app-name[1597:395115] LOG SocketIOClient: Handling event: ping with data: []
2022-09-16 18:05:54.827029+0200 app-name[1597:395444] LOG SocketEnginePolling: Doing polling GET https://<our-socket-url>/socket.io/?transport=polling&b64=1&EIO=4&sid=MmDRjwTzgXduf3x0AAAE
2022-09-16 18:05:54.827843+0200 app-name[1597:395444] LOG SocketEngine: Writing poll: has data: false
2022-09-16 18:05:54.828001+0200 app-name[1597:395444] LOG SocketEnginePolling: Sending poll: as type: 3
2022-09-16 18:05:54.828180+0200 app-name[1597:395444] LOG SocketEnginePolling: Created POST string: 3
2022-09-16 18:05:54.828575+0200 app-name[1597:395444] LOG SocketEnginePolling: POSTing
2022-09-16 18:05:54.828736+0200 app-name[1597:395444] LOG SocketEnginePolling: Doing polling POST https://<our-socket-url>/socket.io/?transport=polling&b64=1&EIO=4&sid=MmDRjwTzgXduf3x0AAAE
Here the swift code:
public init() {
let url = URL(string: DefaultURL.base)
manager = SocketManager(socketURL: url!, config: [.log(true),
.reconnects(true),
.reconnectAttempts(3)])
socket = manager.socket(forNamespace: DefaultURL.namespace)
socketConnectEvent()
socketDisconnectEvent()
connect()
}
private func socketConnectEvent() {
socket.on(clientEvent: .connect) { [weak self] data, ack in
guard let this = self else { return }
this.isConnected = true
this.observer.onConnect()
}
}
private func socketDisconnectEvent() {
socket.on(clientEvent: .disconnect) { [weak self] data, ack in
guard let this = self else { return }
this.isConnected = false
this.observer.onDisconnect()
this.loginCallback?(false, "Socket disconnect")
this.loginCallback = nil
}
}
public func connect() {
Logger.logInfo("Connecting socket…")
socket.connect(timeoutAfter: 1, withHandler: { [weak self] in
guard let this = self else { return }
Logger.logError("Failed to connect")
this.eventHandler?(.connectionDidFailed)
})
}
Your help will be appreciated