mrniko / netty-socketio

Socket.IO server implemented on Java. Realtime java framework
Apache License 2.0
6.82k stars 1.65k forks source link

No connect packet returned for polling client, 1.7.0 #130

Closed sunng87 closed 10 years ago

sunng87 commented 10 years ago

I'm testing netty-socketio with SocketIO-client 1.0.6, polling transport. The client never gets notification for connect. Then I found the server doesn't send connect packet to client.

From code, I found it runs into the null block of ClientHead.java:

    public ChannelFuture send(Packet packet, Transport transport) {
        TransportState state = channels.get(transport);
        state.getPacketsQueue().add(packet);

        Channel channel = state.getChannel();
        if (channel == null
                || (transport == Transport.POLLING && channel.attr(EncoderHandler.WRITE_ONCE).get() != null)) {
           // run into the null block
            return null;
        }
        return sendPackets(transport, channel);
    }

Could you please take a look if there's anything wrong ?

mrniko commented 10 years ago

could you send me a log trace? set logging level 'trace' for 'com.corundumstudio.socketio' package

sunng87 commented 10 years ago

Logs I can produce:

2014-07-03 18:32:11,905 INFO com.corundumstudio.socketio.SocketIOServer: Session store / pubsub factory used: MemoryStoreFactory (local session store only) 2014-07-03 18:32:11,905 INFO com.corundumstudio.socketio.SocketIOServer: SocketIO server started at port: 9494 2014-07-03 18:32:16,751 DEBUG com.corundumstudio.socketio.handler.AuthorizeHandler: Handshake authorized for sessionId: 0d69c376-4202-4706-80ad-e57898605d14 2014-07-03 18:32:16,751 DEBUG com.corundumstudio.socketio.handler.ClientHead: binding channel: [id: 0x8f855c41, /127.0.0.1:45901 => /127.0.0.1:9494] to transport: POLLING 2014-07-03 18:32:16,799 TRACE com.corundumstudio.socketio.handler.EncoderHandler: Out message: �0{"sid":"0d69c376-4202-4706-80ad-e57898605d14","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000} - sessionId: 0d69c376-4202-4706-80ad-e57898605d14

The server side ConnectListener is successfully triggered.

mrniko commented 10 years ago

Tested locally using 1.0.6 client, with FF and Chrome - all works like a charm. Could you send me an browser log?

sunng87 commented 10 years ago

Wired, I'm using a node script like this:

var io = require('socket.io-client')
var socket = io('http://localhost:9494', {'transports': ['polling', 'websocket']});
socket.on('connect', function(){
  console.log("connected");

  socket.on('test', function(data){
    console.log("received:", data);
    socket.disconnect();
  });
  socket.on('disconnect', function(){
    console.log("disconnected");
  });

  socket.emit("test", {name: "xiaoming"});
});
console.log("started");
mrniko commented 10 years ago

Works with your script too

mrniko commented 10 years ago

What about browser network log? From firebug or chrome dev.console

sunng87 commented 10 years ago

Checked wireshark netty-socketio actually sent response to client. So weird the nodejs doesn't respond. Will close this issue for now.

mrniko commented 10 years ago

Have you tried nodejs server, is it behaves the same?

sunng87 commented 10 years ago

Yes, I tried that on nodejs server. I'm looking into nodejs code to see if there's any issue.

sunng87 commented 10 years ago

Compared with the original socketio server, I think it's because netty-socketio doesn't support b64=1 and always returns binary results.

I'll look into the client if it's possible to turn off b64=1

sunng87 commented 10 years ago

No way to disable b64=1 for CLI socket.io-client as it doesn't support XHR2. It would be great to support this extension but actually this isn't a bug. Thanks for you help in this thread and also the great library!!

mrniko commented 10 years ago

does socketio nodejs client sends "b64=1" in http request or where?

mrniko commented 10 years ago

how do you run CLI socket.io-client, could you give me some instruction for it?

sunng87 commented 10 years ago

My client is at here

  1. Copy package.json and client.js to local
  2. Run npm install in the directory
  3. Change transports in client.js to polling
  4. Run a socket.io server on 9494
  5. node client.js

The nodejs client will check if there's binary support and then add b64=1 to url. The node server works with this well, but it seems netty-socketio doesn't support this extension.

mrniko commented 10 years ago

Thanks for your example! I have fixed this issue. Please check

sunng87 commented 10 years ago

Confirmed, it works. Thanks for fixing this issue.

sunng87 commented 10 years ago

Hi Nikita, a release for this fix will be great.

BTW, you can add us AVOS Cloud as a user in the README.

mrniko commented 10 years ago

i read my mind! i just released 1.7.1 ;)

sunng87 commented 10 years ago

:+1: Thanks!!