TakahikoKawasaki / nv-websocket-client

High-quality WebSocket client implementation in Java.
Apache License 2.0
2.03k stars 293 forks source link

support keep alive? #142

Open alanywlee opened 6 years ago

alanywlee commented 6 years ago

Dear Sir,

I found sometime websocket server dead abnormally (e.g., blue screen for some reason), websocket client is not aware server was actually dead unless client sent some data to server and got exception.

If there any example to make client enable keep alive feature, even server dead abnormally, it will detect session closed when heartbeat sent failure.

BR.

Alan

TakahikoKawasaki commented 6 years ago

WebSocket protocol uses HTTP only during the connection establishment. After a connection is established, it's just a pure socket communication. So, HTTP's Keep-Alive won't work. If you want to detect disconnection earlier, why don't you send ping or pong frames periodically? See "Send Ping/Pong Frames Periodically" in the JavaDoc of WebSocket class for details.

alanywlee commented 6 years ago

Dear Takahiko,

Ping/pong frame is exactly what I need. Thanks a lots for your help.

Have a nice day Best regards,

Alan

2018-06-01 1:45 GMT+08:00 Takahiko Kawasaki notifications@github.com:

WebSocket protocol uses HTTP only during the connection establishment. After a connection is established, it's just a pure socket communication. So, HTTP's Keep-Alive won't work. If you want to detect disconnection earlier, why don't you send ping or pong frames periodically? See "Send Ping/Pong Frames Periodically" in the JavaDoc of WebSocket class for details.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/TakahikoKawasaki/nv-websocket-client/issues/142#issuecomment-393615998, or mute the thread https://github.com/notifications/unsubscribe-auth/AF8ITGhjIAkIV03MZIbXDGWGE6uMaLQIks5t4CxPgaJpZM4RagQC .

-- Have a nice day Thanks and Best regards,

Alan