WIP4 système de connection à plusieurs utilisateurs
This commit is contained in:
parent
17e9a0b650
commit
fbcef32a35
1 changed files with 13 additions and 9 deletions
|
@ -107,8 +107,10 @@ class ConnectionListenerThread extends Thread {
|
|||
DatagramSocket requestSocket;
|
||||
DatagramSocket responseSocket;
|
||||
|
||||
ByteArrayOutputStream bStream;
|
||||
ObjectOutput oo;
|
||||
ByteArrayOutputStream bStream1;
|
||||
ByteArrayOutputStream bStream2;
|
||||
ObjectOutput oo1;
|
||||
ObjectOutput oo2;
|
||||
|
||||
String username;
|
||||
|
||||
|
@ -117,8 +119,10 @@ class ConnectionListenerThread extends Thread {
|
|||
{
|
||||
requestSocket = new DatagramSocket(1234);
|
||||
responseSocket = new DatagramSocket();
|
||||
bStream = new ByteArrayOutputStream();
|
||||
oo = new ObjectOutputStream(bStream);
|
||||
bStream1 = new ByteArrayOutputStream();
|
||||
bStream2 = new ByteArrayOutputStream();
|
||||
oo1 = new ObjectOutputStream(bStream1);
|
||||
oo2 = new ObjectOutputStream(bStream2);
|
||||
|
||||
while(!exit)
|
||||
{
|
||||
|
@ -130,13 +134,13 @@ class ConnectionListenerThread extends Thread {
|
|||
username = new String(request.getData(), 0, request.getLength());
|
||||
InetAddress clientAddress= request.getAddress();
|
||||
|
||||
oo.writeObject(user.getUsers());
|
||||
response1 = bStream.toByteArray();
|
||||
oo1.writeObject(user.getUsers());
|
||||
response1 = bStream1.toByteArray();
|
||||
responsePacket1 = new DatagramPacket(response1, response1.length, clientAddress, 1337);
|
||||
responseSocket.send(responsePacket1);
|
||||
|
||||
oo.writeObject(user.getHosts());
|
||||
response2 = bStream.toByteArray();
|
||||
oo2.writeObject(user.getHosts());
|
||||
response2 = bStream2.toByteArray();
|
||||
responsePacket2 = new DatagramPacket(response2, response2.length, clientAddress, 1338);
|
||||
responseSocket.send(responsePacket2);
|
||||
|
||||
|
@ -234,13 +238,13 @@ public class ClientWindow implements ActionListener {
|
|||
connected = false;
|
||||
else
|
||||
{
|
||||
user.add_to_known_users(username, InetAddress.getLocalHost().getHostAddress());
|
||||
for(int i = 0;i < userList.size();i ++)
|
||||
{
|
||||
System.out.println("Name:" + userList.get(i));
|
||||
System.out.println("Address:" + hostList.get(i));
|
||||
user.add_to_known_users(userList.get(i), hostList.get(i));
|
||||
}
|
||||
user.add_to_known_users(username, InetAddress.getLocalHost().getHostAddress());
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue