source: src/test/java/geniusweb/examples/MyClientEndpoint.java@ 2

Last change on this file since 2 was 1, checked in by bart, 5 years ago

Initial Release

File size: 903 bytes
Line 
1package geniusweb.examples;
2
3import java.io.IOException;
4
5import javax.websocket.ClientEndpoint;
6import javax.websocket.OnError;
7import javax.websocket.OnMessage;
8import javax.websocket.OnOpen;
9import javax.websocket.Session;
10
11@ClientEndpoint
12public class MyClientEndpoint {
13 String received = "";
14
15 public MyClientEndpoint() {
16 }
17
18 @OnOpen
19 public void onOpen(Session session) {
20 System.out.println("Connected to endpoint: " + session);
21 String name = "Duke";
22 System.out.println("Sending message to endpoint: " + name);
23 try {
24 session.getBasicRemote().sendText(name);
25 } catch (IOException e) {
26 // TODO Auto-generated catch block
27 e.printStackTrace();
28 }
29 }
30
31 @OnMessage
32 public void processMessage(String message) {
33 System.out.println("Received message in client: " + message);
34 received = message;
35 }
36
37 @OnError
38 public void processError(Throwable t) {
39 t.printStackTrace();
40 }
41
42}
Note: See TracBrowser for help on using the repository browser.