gimite / web-socket-js

HTML5 Web Socket implementation powered by Flash
BSD 3-Clause "New" or "Revised" License
2.74k stars 490 forks source link

Not receiving heratbeats or messages after connection #149

Open s888 opened 10 years ago

s888 commented 10 years ago

After connection is established. Sometimes the websocket class doesn't receive any heartbeats or any response from server. Not sure if the socket disconnected after connecting but the disconnect event is not triggered on client. The Debug output is:

webSocketLog: connected WebSocket.asSocketConnected webSocketLog: request header: GET /socket.io/1/flashsocket/88775RSOCWQfp31qwgte HTTP/1.1

Upgrade: WebSocket

Connection: Upgrade

Host: xxx

Origin: http://localhost

Cookie:

Sec-WebSocket-Key1: 3_Q4 172582Fcbc4IY2K

Sec-WebSocket-Key2: Y *2M?7 y# 32 496- 1 _ 36

webSocketLog: sent key3: ²?¹N­/M? WebSocket.asOnSocketData webSocketLog: response header: HTTP/1.1 101 WebSocket Protocol Handshake

Upgrade: WebSocket

Connection: Upgrade

Sec-WebSocket-Origin: http://localhost

Sec-WebSocket-Location: xxx

WebSocket.asOnSocketData webSocketLog: reply digest: ú{"??£y?ç1N]%? WebSocket.asOnSocketData webSocketLog: received: 1:: webSocketLog: sent: 5:::{xxx}

The message was sent but there wasn't any response or heartbeat after that.

The trace 'WebSocket.asOnSocketData 'is in this function: private function onSocketData(event:ProgressEvent):void { trace('WebSocket.asOnSocketData'); var pos:int = buffer.length;

This doesn't happen always though.

Please Help.

gimite commented 10 years ago

I'm not exactly sure why, but it seems you are using somewhat old version of the library, because it speaks old WebSocket protocol. It may be fixed by using the latest version of the library. It requires the server to speak RFC version of WebSocket protocol, though.

s888 commented 10 years ago

Thanks for the response.

I built WebSocket.swc from flash-src just 2 - 3 months back. I am using node.js socket.io on the server. I don't think socket.io supports rfc draft.

Also, there server console has many warnings like 'invalid web socket connection' and 'invalid key'.

I am using this library upon my flex AIR app and for some random clients the Websocket class doesn't establish any connection and it just raises a websocket.close event.

I guess these issues are related.

reklis commented 10 years ago

Socket io is not standard web sockets. It is more than that. You will need to switch to a different server library or a different client library.