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

This commit is contained in:
Leonie Gallois 2021-02-13 22:09:42 +01:00
parent e6a90adedd
commit b361b36064
3 changed files with 78 additions and 0 deletions

View file

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

View file

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

View file

@ -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<Chat> connexions_chat=new ArrayList<Chat>();
private ArrayList<MatchingId> annuaire_extern_users=new ArrayList<MatchingId>();
private ArrayList<MatchingId> annuaire_intern_users=new ArrayList<MatchingId>();
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();
}
}