nuclearace / Socket.IO-Client-Swift

socket.io-client for Swift
Other
361 stars 53 forks source link

socket connection issues #166

Closed sunil-chayagol closed 6 years ago

sunil-chayagol commented 6 years ago

i am able to connect to the server.but event handlers are not called.

let manager = SocketManager(socketURL: URL(string: "ws://192.168.0.121:8080")!, config: ["connectParams": ["token": token]]) socket = SocketIOClient(manager: manager, nsp: "/location") globalSocket = manager.defaultSocket

    print("TOKEN",token)
    print("MANAGER",manager)
    print("SOCKET",socket)
    print("GLOBAL SOCKET",globalSocket)

    socket?.on(clientEvent: .connect, callback: {[weak self]  data, ack in
        print("socket connected")
    })

    socket?.on("connect") {[weak self] data, ack in
        print("namespace socket connected")
        //      print(data)
    }
    globalSocket?.on("connect") {[weak self] data, ack in
        print("Global socket connected")

// print(data) }

    globalSocket?.on("server.version") {[weak self] data, ack in
        print("Response for server.version")

// print(data) }

    globalSocket?.connect()
    socket?.connect()
nuclearace commented 6 years ago

@sunil-chayagol You shouldn't be manually creating the clients. Use the manager's socket(forNamespace:) method, or the defaultSocket property.

nuclearace commented 6 years ago

Also the manager must be kept around, if it gets released, it will bring down the connections.