Bharath Reddy
Bharath Reddy

Reputation: 746

(SocketIO.Swift) .connect call back is called but not connected to server

I am trying to connect to server using SocketIO for swift. When i try to connect I am getting callback from .connect event but from server side I am not getting any hit. Do I have to add some permissions for this? I already added App Transport Security(allow arbitrary loads to true) setting in plist. Below is my swift code

            let config = URLSessionConfiguration.default
            let cookies = config.httpCookieStorage?.cookies

            print(cookies)

            self.socket = SocketIOClient.init(socketURL: URL.init(string: <server url>)!, config: [.log(true),.cookies(cookies!)])


            self.socket?.on(clientEvent: .connect, callback: {

                data,ack in

                print(data,ack)
                self.socket?.emit("adduser", <sessionData>)
                print("status: \(self.socket?.status.rawValue)" )
            })

            self.socket?.on(clientEvent: .error, callback: {

                data,ack in

                print(data,ack)

            })

            self.socket?.on("livelocation", callback: {

                data,ack in

                print(data,ack)
            })

            self.socket?.connect()

There are no Server logs when I try to connect, when using emit and when I try to listen to event.

Upvotes: 1

Views: 1408

Answers (1)

Bharath Reddy
Bharath Reddy

Reputation: 746

Finally I was able to identify the problem. The problem was namespace. In the server they were using a namespace. So instead of sending the entire thing as url, I had to use .nsp("\namespacename") option. Then it is working fine.

Upvotes: 1

Related Questions