issue with websocket ping/pong

1,268 views
Skip to first unread message

lce

unread,
Mar 31, 2016, 11:24:56 AM3/31/16
to vert.x
Hello,
I am trying to do Server initiated Websocket ping / pong. - i have forced my way into sending the ping, but unfortunately the pong returned by the client is ignored.
i can send the ping  with code like this :
WebSocketFrameImpl frame = new WebSocketFrameImpl(FrameType.PING,io.netty.buffer.Unpooled.copyLong(System.currentTimeMillis()));
ws.writeFrame(frame);

Unfortunately the HttpServerImpl.java  swallows the PONG answer.

        case PING:
              // Echo back the content of the PING frame as PONG frame as specified in RFC 6455 Section 5.5.2
              ch.writeAndFlush(new WebSocketFrameImpl(FrameType.
PONG, wsFrame.getBinaryData()));
              break;
            case PONG:
              // Just ignore it
              break;

So I believe it would be useful if PONG case is also passed to upper layer.  (and ease the ping sending also)  what do you think ?

My rational being this is that i am dealing with long websocket connection (so idle not an option) toward mobile device that may loose connection without properly closing them..
when server writes to such (unattended) websocket there is no error.( if i could get such error it would even be better for me).
 and I would like to avoid to have to implement it on top of the the text/binary frame when already available and implemented in client websocket impl) .

thx
lce.
ps : sorry if some of you see this as a resend- first version fired too quickly.

Tim Fox

unread,
Mar 31, 2016, 11:33:16 AM3/31/16
to ve...@googlegroups.com
I'd recommend searching on this group as very similar questions have been asked and answered before.

Short answer: Use idle timeout and there should be no need to handle the pong yourself
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/65fc96b7-dd43-49be-9d6a-dade851fe618%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

lce

unread,
Mar 31, 2016, 12:21:36 PM3/31/16
to vert.x
Thanks Tim.
Actually i did look  and i did try the idle setting but as i am dealing with long connection, no data for some time is ok, and at the same time i do need to be aware quickly when a client is no longer around. so idle is not suitable.
I guess the best current option is to do it with a custom protocol on top of the ws.
kr

Tim Fox

unread,
Mar 31, 2016, 12:50:03 PM3/31/16
to ve...@googlegroups.com
If you could handle the pong yourself what would you do with it that's not already done by the idle timeout?

I guess you would close the websocket if you didn't receive a pong within a timeout? Which is exactly what the idle timeout does.

I think I am missing something here...

lce

unread,
Mar 31, 2016, 1:34:26 PM3/31/16
to vert.x
Thanks tim, Yes i would close (and also possibly notify the device with vendor notification- but this could also be done handling the socket closing triggered by the idle).

The issue with idle is that i would need to set it to ~ minute(s) to detect soon that a client is leaving,  but no data for minute is normal. So idle will actually close a lot of valid connection. (also i would probably need to set it dynamically)

I guess the real problem here is that the server can write a lot to the (unattended) socket without any exception being raised.

afterward the proper way may be a complex custom ACK mechanism, but i was currently willing to avoid it and would only trigger ping/pong to test a socket when no upward activity on the socket)
kr.

Tim Fox

unread,
Mar 31, 2016, 1:38:53 PM3/31/16
to ve...@googlegroups.com
On 31/03/16 18:34, lce wrote:
Thanks tim, Yes i would close (and also possibly notify the device with vendor notification- but this could also be done handling the socket closing triggered by the idle).

The issue with idle is that i would need to set it to ~ minute(s) to detect soon that a client is leaving,  but no data for minute is normal. So idle will actually close a lot of valid connection. (also i would probably need to set it dynamically)

No, it wouldn't close any valid connections. The pings count as data and would keep the connection open. The connections would only be closed if no packets are sent/received on the connection within the timeout.



I guess the real problem here is that the server can write a lot to the (unattended) socket without any exception being raised.

Unfortunately that's just the way TCP works.

lce

unread,
Mar 31, 2016, 6:44:06 PM3/31/16
to vert.x
Thanks. it took me some time to figure out which 'ping' you were referring to. Yes it would work if i could dynamically change the idle timeout value per socket but even then it would not be as flexible as handling the ping / pong myself.
so lets not waste your time on it ;-) . i'll move to custom ping pong protocol protocol and live with it.
Thanks for your great support.
lce   

Le jeudi 31 mars 2016 19:38:53 UTC+2, Tim Fox a écrit :
On 31/03/16 18:34, lce wrote:
Thanks tim, Yes i would close (and also possibly notify the device with vendor notification- but this could also be done handling the socket closing triggered by the idle).

The issue with idle is that i would need to set it to ~ minute(s) to detect soon that a client is leaving,  but no data for minute is normal. So idle will actually close a lot of valid connection. (also i would probably need to set it dynamically)

No, it wouldn't close any valid connections. The pings count as data and would keep the connection open. The connections would only be closed if no packets are sent/received on the connection within the timeout.
(...)
Reply all
Reply to author
Forward
0 new messages