public static void main(String[] args) throws IOException {
int port = Integer.parseInt(args[0]);
HttpClient httpClient = new HttpClient();
/////////////////////////
// with handler
IWebSocketHandler handler = new IWebSocketHandler() {
public void onMessage(IWebSocketConnection con) throws IOException {
WebSocketMessage msg = con.readMessage();
System.out.println(msg);
}
public void onDisconnect(IWebSocketConnection con) throws IOException { }
public void onConnect(IWebSocketConnection con) throws IOException, UnsupportedProtocolException { }
};
IWebSocketConnection webSocketConnection = httpClient.openWebSocketConnection("ws://localhost:" + port, "com.example.echo", handler);
webSocketConnection.writeMessage(new TextMessage("0123456789"));
////////////////////////////////////////////
// without handler
IWebSocketConnection webSocketConnection2 = httpClient.openWebSocketConnection("ws://localhost:" + port, "com.example.echo");
webSocketConnection2.writeMessage(new TextMessage("0123456789"));
WebSocketMessage msg = webSocketConnection2.readMessage();
Assert.assertEquals("0123456789", msg.toString());