Skip to content

Instantly share code, notes, and snippets.

@matzew
Created February 6, 2014 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matzew/8845066 to your computer and use it in GitHub Desktop.
Save matzew/8845066 to your computer and use it in GitHub Desktop.

Plain WS works, pretty simple:

final WebSocketClient wsc = new WebSocketClient(new URI("ws://echo.websocket.org")) {
    @Override
    public void onOpen(ServerHandshake handshakedata) {
      System.out.println("connected");
    }

    @Override
    public void onMessage(String message) {
    }

    @Override
    public void onClose(int code, String reason, boolean remote) {
      System.out.println("closed");
    }

    @Override
    public void onError(Exception ex) {
      ex.printStackTrace();
    }
};

wsc.connect();

Trying to use wss protocol (e.g. final WebSocketClient wsc = new WebSocketClient(new URI("wss://echo.websocket.org")) {....} is not that simple...

A "serious" amount of code is needed: https://github.com/TooTallNate/Java-WebSocket/blob/9b0a4b8c182bbe3f384d8ee8ede54eb754900bf5/src/main/example/SSLClientExample.java#L62-L85

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment