An example to demonstrate how to write a WebSocket client. This example sends a stream of 10 websocket frames to the
specified server and expects 10 websocket frames in response.
There are three ways of running this example:
Default
The default way is to just run this class with no arguments, which will start a server (
WebSocketEchoServer)
on an ephemeral port and then send an HTTP request to that server and print the response.
If you want to see how
WebSocketEchoServer work, you can run
WebSocketEchoServer by yourself and
then pass the port on which the server started to this class as a program argument:
java io.reactivex.netty.examples.http.ws.echo.WebSocketEchoClient [server port]
Existing HTTP server
You can also use this client to send a GET request "/ws" to an existing HTTP server (different than
WebSocketEchoServer) by passing the port and host of the existing server similar to the case above:
java io.reactivex.netty.examples.http.ws.echo.WebSocketEchoClient [server port]
If the server host is omitted from the above, it defaults to "127.0.0.1"
In all the above usages, this client will print the response received from the server.