From b361b36064b38211aa17d130955290b02c05125f Mon Sep 17 00:00:00 2001 From: Leonie Gallois Date: Sat, 13 Feb 2021 22:09:42 +0100 Subject: [PATCH] =?UTF-8?q?Transf=C3=A9rer=20les=20fichiers=20vers=20'Appl?= =?UTF-8?q?ication/src/server/ws'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/src/server/ws/Chat.java | 7 +++ Application/src/server/ws/MatchingId.java | 8 +++ Application/src/server/ws/Server.java | 63 +++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 Application/src/server/ws/Chat.java create mode 100644 Application/src/server/ws/MatchingId.java create mode 100644 Application/src/server/ws/Server.java diff --git a/Application/src/server/ws/Chat.java b/Application/src/server/ws/Chat.java new file mode 100644 index 0000000..b47a73b --- /dev/null +++ b/Application/src/server/ws/Chat.java @@ -0,0 +1,7 @@ +package server.ws; + +public class Chat { + private MatchingId User1; + private MatchingId User2; + +} diff --git a/Application/src/server/ws/MatchingId.java b/Application/src/server/ws/MatchingId.java new file mode 100644 index 0000000..33ed15c --- /dev/null +++ b/Application/src/server/ws/MatchingId.java @@ -0,0 +1,8 @@ +package server.ws; + +public class MatchingId { + + private Integer Id; + private String Pseudo; + private int UDPport ; +} diff --git a/Application/src/server/ws/Server.java b/Application/src/server/ws/Server.java new file mode 100644 index 0000000..4eadac2 --- /dev/null +++ b/Application/src/server/ws/Server.java @@ -0,0 +1,63 @@ +package server.ws; + import java.util.ArrayList; + +import javax.websocket.OnClose; + import javax.websocket.OnError; + import javax.websocket.OnMessage; + import javax.websocket.OnOpen; + import javax.websocket.server.ServerEndpoint; + +@ServerEndpoint("/websocketendpoint") +public class Server { + + private ArrayList connexions_chat=new ArrayList(); + private ArrayList annuaire_extern_users=new ArrayList(); + private ArrayList annuaire_intern_users=new ArrayList(); + + + public boolean estUnEntier(String chaine) { + try { + Integer.parseInt(chaine); + } catch (NumberFormatException e){ + return false; + } + + return true; + } + + @OnOpen + public void onOpen(){ + System.out.println("Open Connection ..."); + } + + @OnClose + public void onClose(){ + System.out.println("Close Connection ..."); + } + + @OnMessage + public void onMessage(String message){ + String chara=message.substring(0); + if(chara=="I" ) { + //insertion tab matchinid; + //-----> BROADCAST + } + else if (chara=="P"){ + //insertion tab; + } + else if(estUnEntier(message)) { + String msg="Le Client correspond avec le destinataire numéro: "+message; + System.out.println(msg); + } + else { + System.out.println("Message from the client: " + message); + } + //String echoMsg = "Echo from the server : " + message; + //return echoMsg; + } + + @OnError + public void onError(Throwable e){ + e.printStackTrace(); + } +}