<%@ page import = "java.io.*, java.net.*, java.util.concurrent.*, javax.websocket.*" %> <% // Uncomment the next line to make the code work // Class.forName("org.apache.tomcat.websocket.AsyncChannelGroupUtil$AsyncIOThreadFactory$1"); final CountDownLatch messageLatch = new CountDownLatch(1); final Writer outWriter = out; ContainerProvider. getWebSocketContainer(). connectToServer( new Endpoint() { public void onOpen(Session session, EndpointConfig config) { session.addMessageHandler( new MessageHandler.Whole() { public void onMessage(String text) { try { outWriter.write("Response from echo: " + text); } catch (IOException e) { throw new RuntimeException(e); } messageLatch.countDown(); } } ); } }, ClientEndpointConfig.Builder.create().build(), URI.create("ws://127.0.0.1:8080/examples/websocket/echoProgrammatic")). getBasicRemote(). sendText("Hello World!"); messageLatch.await(); %>