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