serveur code version finale
This commit is contained in:
parent
37b2de9cde
commit
cc82a17bd7
4 changed files with 10 additions and 25 deletions
|
@ -95,15 +95,6 @@ public class CommunicationUDP extends Thread {
|
|||
return null;
|
||||
}
|
||||
|
||||
private int getIndexFromIP(InetAddress ip) {
|
||||
for(int i=0; i < users.size() ; i++) {
|
||||
if(users.get(i).getIp().equals(ip)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void printActiveUsersUDP(PrintWriter out) {
|
||||
for (Utilisateur uIn : users) {
|
||||
out.println("<TH> " + uIn.getPseudo() + ",</TH>");
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.io.IOException;
|
|||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
//import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
|
@ -13,14 +13,14 @@ import messages.*;
|
|||
public class UDPClient {
|
||||
|
||||
private DatagramSocket sockUDP;
|
||||
private InetAddress broadcast;
|
||||
//private InetAddress broadcast;
|
||||
|
||||
public UDPClient(int port) throws SocketException, UnknownHostException {
|
||||
this.sockUDP = new DatagramSocket(port);
|
||||
|
||||
InetAddress localHost = InetAddress.getLocalHost();
|
||||
NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost);
|
||||
this.broadcast = networkInterface.getInterfaceAddresses().get(0).getBroadcast();
|
||||
//InetAddress localHost = InetAddress.getLocalHost();
|
||||
//NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost);
|
||||
//this.broadcast = networkInterface.getInterfaceAddresses().get(0).getBroadcast();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,8 +4,6 @@ import java.io.IOException;
|
|||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import main.Utilisateur;
|
||||
import messages.*;
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.net.InetAddress;
|
|||
import java.net.UnknownHostException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
|
@ -14,9 +15,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import communication.CommunicationUDP;
|
||||
import database.SQLiteManager;
|
||||
import messages.*;
|
||||
import messages.Message.TypeMessage;
|
||||
|
||||
/**
|
||||
* Servlet implementation class ServletPresence
|
||||
|
@ -30,10 +29,9 @@ public class ServletPresence extends HttpServlet implements Observer {
|
|||
|
||||
private CommunicationUDP comUDP;
|
||||
private ArrayList<Utilisateur> remoteUsers;
|
||||
private SQLiteManager sqlManager;
|
||||
private String[] registeredRemoteUsers = {"user1","user2","user3"};
|
||||
|
||||
public ServletPresence() {
|
||||
//A changer en passant aux IP
|
||||
try {
|
||||
comUDP = new CommunicationUDP(3333, 3334, new int[] {2209, 2309, 2409, 3334});
|
||||
} catch (IOException e) {
|
||||
|
@ -47,8 +45,6 @@ public class ServletPresence extends HttpServlet implements Observer {
|
|||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
sqlManager = new SQLiteManager(0);
|
||||
}
|
||||
|
||||
private int getIndexByID(String id) {
|
||||
|
@ -184,7 +180,7 @@ public class ServletPresence extends HttpServlet implements Observer {
|
|||
|
||||
//Si l'id n'existe pas dans la BDD : génère du html pour en informer l'utilisateur
|
||||
try {
|
||||
if (sqlManager.getIDUser(id)==-1) {
|
||||
if (!Arrays.asList(registeredRemoteUsers).contains(id)) {
|
||||
printErrorUnkwownUser(out);
|
||||
}
|
||||
|
||||
|
@ -205,7 +201,7 @@ public class ServletPresence extends HttpServlet implements Observer {
|
|||
}
|
||||
printActiveUsersOnly(out);
|
||||
}
|
||||
} catch (UnknownHostException | SQLException e) {
|
||||
} catch (UnknownHostException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue