socketio / socket.io-client-swift

Other
5.22k stars 842 forks source link

NOT SUCCESSFULLY CONNECTED? #594

Open lazarte opened 7 years ago

lazarte commented 7 years ago

Hi, I successfully setup the SocketIOClient and this seems to be that that the server replied when I connect. But the client doesn't receive response that it was connected. When trying to emit will give me the error that it was not connected. See below codes and logs. Please help.

func connection() {
        let url = URL(string: "SOCKET_URL")!
        socket = SocketIOClient(socketURL: url,
                                     config: [.log(true),
                                              .path("/primus"),
                                              .forceWebsockets(true)
            ])

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

        socket.on("connect") {data, ack in
            print("socket connected")
        }

        socket.connect()
    }

LOG SocketIOClient: Adding handler for event: connect LOG SocketIOClient: Adding engine LOG SocketEngine: Starting engine. Server: SOCKET_URL LOG SocketEngine: Handshaking LOG SocketEngine: Got message: {"type":0,"data":["@HandShake","Hello"]} // Replied from the server LOG SocketIOClient: Handling event: error with data: ["Tried emitting data when not connected"] Any Got event: error, with items: Optional(["Tried emitting data when not connected"])

nuclearace commented 7 years ago

That's a pretty straightforward error. You shouldn't be trying to send something before the connect event is fired. But are you actually connecting to a socket.io server?

lazarte commented 7 years ago

Yes I'm connecting to the primus with socket.io transformer. I got an message from the server so meaning the handshake is successful?

nuclearace commented 7 years ago

That got message doesn't look like something socket.io would send. The first thing socket.io should be sending is a connect packet that has some connection information.

lazarte commented 7 years ago

Actually that message emit from our server. Manually added this code from this pull request 489 seems to trigger the connect event?

nuclearace commented 7 years ago

Are you sure that you're not looking for a straight Websocket client? Because if you're changing to so much that it isn't getting the proper packets to connect you're getting into fork land.

lazarte commented 7 years ago

@nuclearace below is the code for the primus server don't know why the client doesn't trigger the connect event. On the other hand using socket.io works fine. But want to know why its not working with the primus.

var Primus = require('primus') var primus = Primus.createServer({ port: 3002, transformer: 'websockets' }); primus.on('connection', function (spark) { spark.write({"type":0,"data":["@HandShake","Hello"]}); });

nuclearace commented 7 years ago

Does primus follow the socket.io protocol? Because that's the only way this client would work with it.