Browse Source

Transférer les fichiers vers 'Application/src/server/ws'

Leonie Gallois 3 years ago
parent
commit
b361b36064

+ 7
- 0
Application/src/server/ws/Chat.java View File

@@ -0,0 +1,7 @@
1
+package server.ws;
2
+
3
+public class Chat {
4
+	private MatchingId User1;
5
+	private MatchingId User2;
6
+
7
+}

+ 8
- 0
Application/src/server/ws/MatchingId.java View File

@@ -0,0 +1,8 @@
1
+package server.ws;
2
+
3
+public class MatchingId {
4
+
5
+	private Integer Id;
6
+	private String Pseudo;
7
+	private int UDPport ;
8
+}

+ 63
- 0
Application/src/server/ws/Server.java View File

@@ -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
+}

Loading…
Cancel
Save