users@grizzly.java.net

Re: Ping/Pong mechanism in Grizzly 2.1.8 WebSocket API

From: Philipp Tarasiewicz <justphilmusic_at_googlemail.com>
Date: Mon, 9 Jan 2012 19:20:48 +0100

Hi Ryan,

I haven't any code that is worth mentioning, since I've obviously
misinterpreted the related API docs.

My initial thoughts after having studied the docs were like:
Grizzly automatically performs ping/pong cycles every x seconds to maintain
the connection to every connected remote client and correspondingly invokes
the related callback methods in the WebSocketApplication class.
 - onPing(WebSocket socket, byte[] bytes) : Server is about to ping
WebSocket 'socket' by sending 'bytes' bytes.
 - onPong(WebSocket socket, byte[] bytes) : Server has received pong
information 'bytes' from remote client connected to WebSocket 'socket'.

So, I've overriden these methods in my WebSocketApplication subclass (just
for logging purpose), started the server, connected a client to it and have
been expecting that server/client will automatically perform ping/pong
cycles every x seconds.


But finally, after having read your and Justin's responses + having a
closer look at your corresponding code (just cloned the repo), it is
completely enlightening that it could not work this way.

In particular, I've realized how you send the ping / pong frames.
Consequently, it shouldn't be a big deal for me to implement the behavior
that I had initially expected.

Nevertheless, I will also log a feature request. :-)



There is one more question I'm interested in. But, I should probably ask it
in a new thread since it does not related to this topic.

Thank you guys for your help!

Phil

2012/1/9 Ryan Lubke <ryan.lubke_at_oracle.com>

> On 1/9/12 7:19 AM, justphilmusic_at_googlemail.com wrote:
>
>> Hi Ryan!
>>
>> Until now I've just played around with the WebSocketClient included in
>> Grizzly's 2.1.8 WebSocket API. So, it's the websocket version that the
>> WebSocketClient class is using.
>> I haven't used a brower yet.
>>
> To go back to your original question, I've locally tested that pings are
> responded to automatically, however, I'm making some changes to
> make sending pings a little more straight forward.
>
> Can you share your code? Would like to see what you're doing different.
>
>
>> The question is:
>> Does Grizzly's WebSocket implementation perform any connection
>> maintainance / heart-beating under the hood or do I have to implement
>> the logic by myself?
>>
> At this point, there is no heart-beat feature. However, it probably
> wouldn't
> be a bad feature to offer. I would recommend logging a feature request.
>
>
>>
>> Best regards,
>> Phil
>>
>
>