WIP2 système de connection à plusieurs utilisateurs
This commit is contained in:
parent
a745f39e0c
commit
73664235ba
1 changed files with 8 additions and 0 deletions
|
@ -124,7 +124,9 @@ class ConnectionListenerThread extends Thread {
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
System.out.println("Waiting for connection request");
|
||||||
requestSocket.receive(request);
|
requestSocket.receive(request);
|
||||||
|
System.out.println("Received a request!");
|
||||||
username = new String(request.getData(), 0, request.getLength());
|
username = new String(request.getData(), 0, request.getLength());
|
||||||
InetAddress clientAddress= request.getAddress();
|
InetAddress clientAddress= request.getAddress();
|
||||||
|
|
||||||
|
@ -225,12 +227,17 @@ public class ClientWindow implements ActionListener {
|
||||||
userList = (ArrayList<String>) userListStream.readObject();
|
userList = (ArrayList<String>) userListStream.readObject();
|
||||||
hostList = (ArrayList<String>) hostListStream.readObject();
|
hostList = (ArrayList<String>) hostListStream.readObject();
|
||||||
|
|
||||||
|
System.out.println(userList.size() + "users currently connected");
|
||||||
|
|
||||||
if (userList.indexOf(username) != -1)
|
if (userList.indexOf(username) != -1)
|
||||||
connected = false;
|
connected = false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
user.add_to_known_users(username, InetAddress.getLocalHost().getHostAddress());
|
||||||
for(int i = 0;i < userList.size();i ++)
|
for(int i = 0;i < userList.size();i ++)
|
||||||
{
|
{
|
||||||
|
System.out.println(userList.get(i));
|
||||||
|
System.out.println(hostList.get(i));
|
||||||
user.add_to_known_users(userList.get(i), hostList.get(i));
|
user.add_to_known_users(userList.get(i), hostList.get(i));
|
||||||
}
|
}
|
||||||
connected = true;
|
connected = true;
|
||||||
|
@ -238,6 +245,7 @@ public class ClientWindow implements ActionListener {
|
||||||
}
|
}
|
||||||
catch(SocketTimeoutException e)
|
catch(SocketTimeoutException e)
|
||||||
{
|
{
|
||||||
|
user.add_to_known_users(username, InetAddress.getLocalHost().getHostAddress());
|
||||||
System.out.println("Reply timed out");
|
System.out.println("Reply timed out");
|
||||||
connected = true;
|
connected = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue