package geniusweb.examples; import java.io.IOException; import javax.websocket.ClientEndpoint; import javax.websocket.OnError; import javax.websocket.OnMessage; import javax.websocket.OnOpen; import javax.websocket.Session; @ClientEndpoint public class MyClientEndpoint { String received = ""; public MyClientEndpoint() { } @OnOpen public void onOpen(Session session) { System.out.println("Connected to endpoint: " + session); String name = "Duke"; System.out.println("Sending message to endpoint: " + name); try { session.getBasicRemote().sendText(name); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @OnMessage public void processMessage(String message) { System.out.println("Received message in client: " + message); received = message; } @OnError public void processError(Throwable t) { t.printStackTrace(); } }