WIP7 système de connection à plusieurs utilisateurs
This commit is contained in:
parent
fdc002ff80
commit
b518621a88
1 changed files with 17 additions and 2 deletions
|
@ -164,7 +164,20 @@ class ConnectionListenerThread extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class ClientWindow implements ActionListener {
|
public class ClientWindow implements ActionListener {
|
||||||
|
String getLocalIP() {
|
||||||
|
String ip = "";
|
||||||
|
try(final DatagramSocket socket = new DatagramSocket()){
|
||||||
|
socket.connect(InetAddress.getByName("8.8.8.8"), 10002);
|
||||||
|
ip = socket.getLocalAddress().getHostAddress();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("niiiiiiiikkk");
|
||||||
|
}
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
JFrame chatWindow;
|
JFrame chatWindow;
|
||||||
|
|
||||||
JPanel chatPanel;
|
JPanel chatPanel;
|
||||||
|
@ -179,6 +192,7 @@ public class ClientWindow implements ActionListener {
|
||||||
|
|
||||||
ClientWindow()
|
ClientWindow()
|
||||||
{
|
{
|
||||||
|
|
||||||
String username = "";
|
String username = "";
|
||||||
Boolean connected = false;
|
Boolean connected = false;
|
||||||
DatagramSocket connectionSocket;
|
DatagramSocket connectionSocket;
|
||||||
|
@ -252,7 +266,8 @@ public class ClientWindow implements ActionListener {
|
||||||
}
|
}
|
||||||
catch(SocketTimeoutException e)
|
catch(SocketTimeoutException e)
|
||||||
{
|
{
|
||||||
user.add_to_known_users(username, connectionSocket.getLocalAddress().getHostAddress());
|
user.add_to_known_users(username, getLocalIP());
|
||||||
|
System.out.println(getLocalIP());
|
||||||
System.out.println("Reply timed out");
|
System.out.println("Reply timed out");
|
||||||
connected = true;
|
connected = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue