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(); + } +}