|
@@ -0,0 +1,63 @@
|
|
1
|
+package server.ws;
|
|
2
|
+ import java.util.ArrayList;
|
|
3
|
+
|
|
4
|
+import javax.websocket.OnClose;
|
|
5
|
+ import javax.websocket.OnError;
|
|
6
|
+ import javax.websocket.OnMessage;
|
|
7
|
+ import javax.websocket.OnOpen;
|
|
8
|
+ import javax.websocket.server.ServerEndpoint;
|
|
9
|
+
|
|
10
|
+@ServerEndpoint("/websocketendpoint")
|
|
11
|
+public class Server {
|
|
12
|
+
|
|
13
|
+ private ArrayList<Chat> connexions_chat=new ArrayList<Chat>();
|
|
14
|
+ private ArrayList<MatchingId> annuaire_extern_users=new ArrayList<MatchingId>();
|
|
15
|
+ private ArrayList<MatchingId> annuaire_intern_users=new ArrayList<MatchingId>();
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+ public boolean estUnEntier(String chaine) {
|
|
19
|
+ try {
|
|
20
|
+ Integer.parseInt(chaine);
|
|
21
|
+ } catch (NumberFormatException e){
|
|
22
|
+ return false;
|
|
23
|
+ }
|
|
24
|
+
|
|
25
|
+ return true;
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+ @OnOpen
|
|
29
|
+ public void onOpen(){
|
|
30
|
+ System.out.println("Open Connection ...");
|
|
31
|
+ }
|
|
32
|
+
|
|
33
|
+ @OnClose
|
|
34
|
+ public void onClose(){
|
|
35
|
+ System.out.println("Close Connection ...");
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+ @OnMessage
|
|
39
|
+ public void onMessage(String message){
|
|
40
|
+ String chara=message.substring(0);
|
|
41
|
+ if(chara=="I" ) {
|
|
42
|
+ //insertion tab matchinid;
|
|
43
|
+ //-----> BROADCAST
|
|
44
|
+ }
|
|
45
|
+ else if (chara=="P"){
|
|
46
|
+ //insertion tab;
|
|
47
|
+ }
|
|
48
|
+ else if(estUnEntier(message)) {
|
|
49
|
+ String msg="Le Client correspond avec le destinataire numéro: "+message;
|
|
50
|
+ System.out.println(msg);
|
|
51
|
+ }
|
|
52
|
+ else {
|
|
53
|
+ System.out.println("Message from the client: " + message);
|
|
54
|
+ }
|
|
55
|
+ //String echoMsg = "Echo from the server : " + message;
|
|
56
|
+ //return echoMsg;
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ @OnError
|
|
60
|
+ public void onError(Throwable e){
|
|
61
|
+ e.printStackTrace();
|
|
62
|
+ }
|
|
63
|
+}
|