SockJS close event - reason

瀏覽次數:179 次
跳到第一則未讀訊息

Gilad Artzi

未讀,
2015年4月2日 上午11:25:442015/4/2
收件者:soc...@googlegroups.com
Hello,

I have a question about SockJS close event - could I possibly know the close reason?
In the client side, I get an object as an argument to the onclose callback function - is there anything like that on the node side?

I am giving my clients a time frame in which I save their session data, and I need this time frame to be dynamic - If the client was disconnected due to a ping timeout, their "grace period" should be longer, etc

BTW, I really like the SockJS project, the xhr_streaming transport emulates WebSocket in the best way I have found! :-)

Thanks very much,
Gilad

Chris-S

未讀,
2015年6月23日 晚上9:59:172015/6/23
收件者:soc...@googlegroups.com
The general rule of thumb is to create your own ping code - This handles all sorts of possible socket problems, such as zombie sessions.
I get the client to send a ping every 20 seconds, and node to check the array of client ping times every 35 seconds, if the age is over a certain time, the connection is terminated.
Additionally I employ a synchronous ajax request on the browser close event, to send a PHP instant goodbye event back to node.
This works on refresh and on closure of tabs. (stackoverflow has info on it somewhere, else i'll be happy to post the code)

-Chris
回覆所有人
回覆作者
轉寄
0 則新訊息