refactoring: modification de la classe User (fixed)
This commit is contained in:
parent
28d750584d
commit
de1ffdb4a8
2 changed files with 21 additions and 11 deletions
|
@ -129,14 +129,18 @@ class ConnectionListenerThread extends Thread {
|
|||
username = new String(request.getData(), 0, request.getLength());
|
||||
InetAddress clientAddress= request.getAddress();
|
||||
System.out.println("Received a request from " + username + "@" + clientAddress.getHostAddress());
|
||||
|
||||
if(known_users.indexOf(new User(username, clientAddress.getHostAddress())) != -1)
|
||||
{
|
||||
oo.writeObject(known_users);
|
||||
response1 = bStream.toByteArray();
|
||||
responsePacket = new DatagramPacket(response1, response1.length, clientAddress, 1337);
|
||||
responseSocket.send(responsePacket);
|
||||
System.out.println("Response:");
|
||||
|
||||
for(User user:known_users)
|
||||
{
|
||||
System.out.println(user.getName() + ":" + user.getAddress());
|
||||
}
|
||||
oo.writeObject(known_users);
|
||||
response1 = bStream.toByteArray();
|
||||
responsePacket = new DatagramPacket(response1, response1.length, clientAddress, 1337);
|
||||
responseSocket.send(responsePacket);
|
||||
if(known_users.indexOf(new User(username, clientAddress.getHostAddress())) == -1)
|
||||
{
|
||||
known_users.add(new User(username, clientAddress.getHostAddress()));
|
||||
}
|
||||
|
||||
|
@ -146,7 +150,8 @@ class ConnectionListenerThread extends Thread {
|
|||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("nik!!");
|
||||
e.printStackTrace();
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -228,13 +233,13 @@ public class NetworkClient {
|
|||
System.out.println(userList.get(i).getName() + " : " + userList.get(i).getAddress());
|
||||
known_users.add(userList.get(i));
|
||||
}
|
||||
known_users.add(new User(username, getLocalIP()));
|
||||
known_users.add(new User(username, "25.67.234.235"));
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
catch(SocketTimeoutException e)
|
||||
{
|
||||
known_users.add(new User(username, getLocalIP()));
|
||||
known_users.add(new User(username, "25.67.234.235"));
|
||||
System.out.println("Reply timed out");
|
||||
connected = true;
|
||||
}
|
||||
|
@ -252,6 +257,11 @@ public class NetworkClient {
|
|||
{
|
||||
user.setName(username);
|
||||
ReceiveThread t2 = new ReceiveThread(1237, chatText);
|
||||
for(User a:known_users)
|
||||
{
|
||||
System.out.println(a.getName() + ":" + a.getAddress());
|
||||
}
|
||||
|
||||
ConnectionListenerThread t3 = new ConnectionListenerThread(known_users);
|
||||
t2.start();
|
||||
t3.start();
|
||||
|
|
|
@ -3,7 +3,7 @@ package chat;
|
|||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class User {
|
||||
public class User implements Serializable{
|
||||
|
||||
private String name;
|
||||
private String address;
|
||||
|
|
Loading…
Reference in a new issue