-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJooc.java
49 lines (44 loc) · 1.39 KB
/
Jooc.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// package websocket.client;
import java.net.URI;
import javax.websocket.*;
@ClientEndpoint
public class Jooc {
private static Object waitLock = new Object ();
@OnMessage
public void onMessage( String message) {
System.out.println ("Received msg: " + message);
}
private static void waitForTerminationSignal () {
synchronized (waitLock) {
try {
waitLock.wait ();
}
catch (InterruptedException exception) {
exception.printStackTrace ();
}
}
}
public static void main (String [] args) {
WebSocketContainer container = null;//
Session session = null;
try{
container = ContainerProvider.getWebSocketContainer ();
session = container.connectToServer (Jooc.class, URI.create ("ws://localhost:6666"));
session.getAsyncRemote () .sendText ("[\"register\", \"master\", \"ABN\"]");
waitForTerminationSignal ();
}
catch (Exception exception) {
exception.printStackTrace ();
}
finally {
if (session != null) {
try {
session.close ();
}
catch (Exception exception) {
exception.printStackTrace ();
}
}
}
}
}