Socket.io-client-swift: Client is stuck on 'Connecting' status

Created on 28 Jul 2016  路  3Comments  路  Source: socketio/socket.io-client-swift

Here is the code I'm using in my ViewController:

var socket:SocketIOClient?

//To print the connection status periodically
var timer:NSTimer?

override func viewDidLoad() {
    super.viewDidLoad()


    self.timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(self.printStatus), userInfo: nil, repeats: true)


    let url = "https://test.myurl:443"

    self.socket  = SocketIOClient(
        socketURL: NSURL(string: url)!,
        options: [
            .Log(true),
            .ForceWebsockets(false),
            .ForcePolling(true),
            .Secure(true),
            .Path("/my-path/socket.io"),
            .ExtraHeaders(["Authorization" : "Basic encoded_authorization"])
            ])

    self.socket!.on("error"){
        data, ack in
        print("Event: Error")
    }

    self.socket!.on("disconnect"){
        data, ack in
        print("Event: disconnect")
    }

    self.socket!.on("reconnect"){
        data, ack in
        print("Event: disconnect")
    }

    self.socket!.on("reconnectAttempt"){
        data, ack in
        print("Event: reconnectAttempt")
    }

    self.socket!.on("connect") {data, ack in
        print("socket is connected")

    }

    self.socket?.onAny(){
        any in
        print("Any event: \(any)")
    }

    self.socket!.connect()

}



func printStatus()
{
    switch self.socket!.status{
    case .Connected:
        print("status: connected")
    case .Connecting:
        print("status: connecting")
    case .Disconnected:
        print("status: disconnected")
    case .NotConnected:
        print("status: notconnected")

    }
}`

And this is the console:

2016-07-28 18:56:17.757 SocketIOTest[1136:511024] LOG SocketIOClient: Adding handler for event: error
2016-07-28 18:56:17.758 SocketIOTest[1136:511024] LOG SocketIOClient: Adding handler for event: disconnect
2016-07-28 18:56:17.759 SocketIOTest[1136:511024] LOG SocketIOClient: Adding handler for event: reconnect
2016-07-28 18:56:17.759 SocketIOTest[1136:511024] LOG SocketIOClient: Adding handler for event: reconnectAttempt
2016-07-28 18:56:17.759 SocketIOTest[1136:511024] LOG SocketIOClient: Adding handler for event: connect
2016-07-28 18:56:17.759 SocketIOTest[1136:511024] LOG SocketIOClient: Adding engine
2016-07-28 18:56:17.760 SocketIOTest[1136:511024] LOG SocketEngine: Starting engine. Server: https://test.myurl:443
2016-07-28 18:56:17.760 SocketIOTest[1136:511024] LOG SocketEngine: Handshaking
2016-07-28 18:56:17.761 SocketIOTest[1136:511067] LOG SocketEnginePolling: Doing polling request
2016-07-28 18:56:18.027 SocketIOTest[1136:511070] LOG SocketEnginePolling: Got polling response
status: connecting
status: connecting
status: connecting
status: connecting
status: connecting
status: connecting
status: connecting
.....

I can't find this issue somewhere else. What can I try to get ahead with this?
I have no problem connecting using your JavaScript framework.

Thank you

question

Most helpful comment

In your path, add an /

All 3 comments

In your path, add an /

That's it :)
Thank you for your quick help!

@nuclearace i have the save problem

var url = "https://test.tx/"
let manager = SocketManager(socketURL: URL(string: url )!, config: [.log(true), .compress])
let socket = manager.defaultSocket
socket.on(clientEvent: .connect) {data, ack in
print("socket connected")
}
socket.onAny{
print("got event: ($0.event) with items ($0.items)")
}
socket.connect()
var x = 0
while true {
print(socket.status)
x = x+1
print(x)
}
it stuck in connecting
how can i solve it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Seonift picture Seonift  路  4Comments

MihaelIsaev picture MihaelIsaev  路  6Comments

astrike30 picture astrike30  路  6Comments

Yelles picture Yelles  路  5Comments

heisian picture heisian  路  4Comments