socketio / socket.io-client-swift

Other
5.22k stars 843 forks source link

Unable to connect to socket #1017

Closed Ketan-Wadyalkar closed 6 years ago

Ketan-Wadyalkar commented 6 years ago
       let manager = SocketManager(socketURL: URL(string: "http://xxx.xxx.x.x:5000")!, config: [.log(true)])

    socket = manager.defaultSocket

   // Below method is never called.
         socket.on(clientEvent: .connect) {data, ack in
             print("socket connected")
        }

    socket.on(clientEvent: .error) {data, ack in
        print("socket error")
    }

    socket.connect()

    socket.onAny {
        print("Got event: \($0.event), with items: \(String(describing: $0.items))")
    }

I am missing on something in my code ? How to check if socket was connected successfully or there was an error ? Socket server is in an android app. Socket never gets connected from my iOS app.

Below is the debug log

2018-05-16 12:04:18.050972+0530 SocketDemo[337:30416] LOG SocketIOClient{/}: Adding handler for event: connect 2018-05-16 12:04:18.051769+0530 SocketDemo[337:30416] LOG SocketIOClient{/}: Adding handler for event: error 2018-05-16 12:04:18.052679+0530 SocketDemo[337:30416] LOG SocketIOClient{/}: Handling event: statusChange with data: [connecting] 2018-05-16 12:04:18.052720+0530 SocketDemo[337:30416] LOG SocketIOClient{/}: Joining namespace / 2018-05-16 12:04:18.052747+0530 SocketDemo[337:30416] LOG SocketManager: Tried connecting socket when engine isn't open. Connecting 2018-05-16 12:04:18.052772+0530 SocketDemo[337:30416] LOG SocketManager: Adding engine 2018-05-16 12:04:18.055914+0530 SocketDemo[337:30416] LOG SocketIOClient{/}: Adding handler for event: / 2018-05-16 12:04:18.055979+0530 SocketDemo[337:30416] LOG SocketManager: Manager is being released 2018-05-16 12:04:18.056043+0530 SocketDemo[337:30477] LOG SocketEngine: Starting engine. Server: http://xxx.xxx.x.x:5000 2018-05-16 12:04:18.056072+0530 SocketDemo[337:30477] LOG SocketEngine: Handshaking 2018-05-16 12:04:18.057599+0530 SocketDemo[337:30477] LOG SocketEnginePolling: Doing polling GET http://xxx.xxx.x.x:5000/socket.io/?transport=polling&b64=1 2018-05-16 12:04:19.438667+0530 SocketDemo[337:30478] LOG SocketEnginePolling: Got polling response 2018-05-16 12:04:19.442191+0530 SocketDemo[337:30478] LOG SocketEnginePolling: Got poll message: 2018-05-16 12:04:19.444076+0530 SocketDemo[337:30475] LOG SocketEngine: Engine is being released

nuclearace commented 6 years ago

@Ketan-Wadyalkar Please read the FAQ and a little on ARC; the manager is being released from memory as soon as it goes out of scope.

Ketan-Wadyalkar commented 6 years ago

@nuclearace Thanks for quick response and My bad that i didn't checked FAQ before raising this issue. I have updated my code and it's working fine for web-socket but i am facing the above mentioned issue when i try to connect to the socket created by android app. There is no issue in the socket, i am able to connect the socket using android app & Starscream library for iOS. Any suggestion on how to do this using socket.io ? Also it would be really helpful if you can guide me on how to write jsonstring on socket.

Thanks in advance.