bugfixes TCP (bis)

This commit is contained in:
Louis Farina 2021-01-12 18:08:16 +01:00
parent 11c2af4648
commit 4fe854e2f5
2 changed files with 17 additions and 2 deletions

View file

@ -67,7 +67,7 @@ public class ClientWindow implements ActionListener {
messageField.addActionListener(this);
chatWindow.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
network.send(null);
network.disconnect();
}
});

View file

@ -103,6 +103,7 @@ class ReceiveThread extends Thread {
}
socket.close();
dest_sockets.remove(socket);
}
catch(Exception e)
{
@ -154,6 +155,7 @@ class ConnectionListenerThread extends Thread {
InetAddress clientAddress= request.getAddress();
System.out.println("Received a request from " + username + "@" + clientAddress.getHostAddress());
response = "";
for(User u:known_users)
{
response += u.getName() + " ";
@ -165,7 +167,7 @@ class ConnectionListenerThread extends Thread {
response += s.getInetAddress().getHostAddress() + " ";
}
response = response.trim();
System.out.println("Response :" + response);
System.out.println("Response :" + response + "!");
responseBytes = response.getBytes();
responsePacket = new DatagramPacket(responseBytes, responseBytes.length, clientAddress, 1337);
responseSocket.send(responsePacket);
@ -388,4 +390,17 @@ public class NetworkClient {
catch(IOException e){}
}
}
void disconnect()
{
send(null);
for(Socket s:dest_sockets)
{
try
{
s.close();
}
catch(IOException e){}
}
}
}