-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
the java websocket client can't reseived message after 30mins #213
Comments
I'm having a similar issue in another library that uses Java-WebSocket. It doesn't take 30 minutes for it to happen, but if nothing happens for a short period of time (say, 5 minutes), then the connection remains open but the connection quits receiving data. This is happening to me when using the library in an Android app, so I don't know if this is perhaps an Android specific problem? I can see you posted this a couple weeks ago - have you made any progress on finding a solution? |
Unless something else is going on, this seems to be a well known issue that is unrelated to websockets. The WebSocket protocol provides a ping operation that lets you do this ( http://tools.ietf.org/html/rfc6455#section-5.5.2 ), but you could also accomplish this in your application protocol. Using ping in the WebSocket protocol might be more convenient because it requires no changes in your application protocol. This library implements ping and pong, but it does not provide a convenient single method to send pings, it does provide ping/pong listeners. This is how you send a Ping operation: void sendPing(WebSocket conn)
{
conn.sendFrame(new FramedataImpl1(Opcode.PING));
} After you do this, the other party will immediately reply with a pong. What you could do is:
|
Do you think this is something that consumers of this library should have to do, or is this something that should be implemented in the Java-WebSocket library itself? It seems like sending out Ping requests ought to be handled by this library rather than the consumer. Regardless, I really appreciate you providing advice on how to go about implementing this without making any changes to this library, and I may end up doing just that if the library I'm using doesn't implement logic similar to this or this library doesn't get updated to do it on its own. |
As long as it is optional, java-websocket would seem to be the right place to me yes. Or at least make it easier to implement, for example by adding a few methods on the WebSocket interface:
|
This doesn't seem to work when sent from WebSocketClient. Just an FYI. I don't even know if that's allowed by the standards, but I tried, and it failed. |
Client and server should be able to send a ping. If a pong reply is not sent, there is either a bug in this library or my example code (which I did not test 😈). You could test this stuff with wireshark. Look here to figure out what the frames look like: https://tools.ietf.org/html/rfc6455#section-5.2 |
Interesting. I'm not up to all of your levels to be able to diagnose this issue, so I'll merely report back my experience. The ping works perfectly with the server, but with the client, it reports "control frames may no be fragmented" (thank goodness for the typo!). Google leads to this line of code: https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/java/org/java_websocket/drafts/Draft_10.java#L316 If Either way, works for me since it's sufficient that only the servers send pings since only clients will be connected to them, lol. Thank you for that code! |
Could you try this instead: void sendPing(WebSocket conn)
{
FramedataImpl1 frame = new FramedataImpl1(Opcode.PING);
frame.setFin(true);
conn.sendFrame(frame);
} I had expected fin to be set by default, but it is not. |
see #473 |
the java websocket client can't reseived message after 30mins,
is there any option to set the connect time out
The text was updated successfully, but these errors were encountered: