read wss endpoint java

Solutions on MaxInterview for read wss endpoint java by the best coders in the world

showing results for - "read wss endpoint java"
Romeo
24 Feb 2019
1package testapp;
2
3import java.net.URI;
4import java.net.URISyntaxException;
5
6public class TestApp {
7
8    public static void main(String[] args) {
9        try {
10            // open websocket
11            final WebsocketClientEndpoint clientEndPoint = new WebsocketClientEndpoint(new URI("wss://real.okcoin.cn:10440/websocket/okcoinapi"));
12
13            // add listener
14            clientEndPoint.addMessageHandler(new WebsocketClientEndpoint.MessageHandler() {
15                public void handleMessage(String message) {
16                    System.out.println(message);
17                }
18            });
19
20            // send message to websocket
21            clientEndPoint.sendMessage("{'event':'addChannel','channel':'ok_btccny_ticker'}");
22
23            // wait 5 seconds for messages from websocket
24            Thread.sleep(5000);
25
26        } catch (InterruptedException ex) {
27            System.err.println("InterruptedException exception: " + ex.getMessage());
28        } catch (URISyntaxException ex) {
29            System.err.println("URISyntaxException exception: " + ex.getMessage());
30        }
31    }
32}
33