Hello,
I am working with Websocket on client side with Netty.
I have a use case where I need to wait on the client side for server response and timeout if answer does not come in a defined interval.
I have looked at
https://github.com/netty/netty/blob/master/example/src/main/java/io/netty/example/http/websocketx/client/ code comment and there is something not clear for me:
Comment says:
// Send 10 messages and wait for responses
ch.write(new TextWebSocketFrame("Message #" + i));
But it seems it is the following code that makes the client wait for server response:
ch.closeFuture().sync();
Note that in my case I don't want to close the websocket as shown in sample.
So my idea to implement this was to use a CountDownLatch which I would pass to WebSocketClientHandler.
In the equivalent of WebSocketClient, I would wait on latch with timeout.
If WebSocketClientHandler gets a response it would decrement latch and make WebSocketClient continue processing, otherwise timeout would occur.
Is this way of doing it is correct ? Are there better way to do it ?
Thanks for your help
Regards
Philippe