Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.net.URI;
- import javax.websocket.*;
- @ClientEndpoint
- public class Client {
- Session session;
- private final static String url = "ws://echo.websocket.org";
- public static void main(String[] args) throws Exception, IOException {
- WebSocketContainer container = ContainerProvider.getWebSocketContainer();
- System.out.println("connecting...");
- container.connectToServer(Client.class,
- URI.create(url));
- }
- @OnMessage
- public void newMessage(String message, Session session) {
- System.out.println(message);
- }
- @OnOpen
- public void newConnection(Session session) throws IOException {
- this.session = session;
- System.out.println("The connection has been started");
- session.getBasicRemote().sendText("hello");
- }
- @OnClose
- public void disconnection() {
- System.out.println("The connection has been ended");
- }
- }
Add Comment
Please, Sign In to add comment