bugfixes TCP (bis)
This commit is contained in:
父節點
11c2af4648
當前提交
4fe854e2f5
共有 2 個文件被更改,包括 17 次插入 和 2 次删除
|
@ -67,7 +67,7 @@ public class ClientWindow implements ActionListener {
|
||||||
messageField.addActionListener(this);
|
messageField.addActionListener(this);
|
||||||
chatWindow.addWindowListener(new WindowAdapter() {
|
chatWindow.addWindowListener(new WindowAdapter() {
|
||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
network.send(null);
|
network.disconnect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,7 @@ class ReceiveThread extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.close();
|
socket.close();
|
||||||
|
dest_sockets.remove(socket);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
|
@ -154,6 +155,7 @@ class ConnectionListenerThread extends Thread {
|
||||||
InetAddress clientAddress= request.getAddress();
|
InetAddress clientAddress= request.getAddress();
|
||||||
System.out.println("Received a request from " + username + "@" + clientAddress.getHostAddress());
|
System.out.println("Received a request from " + username + "@" + clientAddress.getHostAddress());
|
||||||
|
|
||||||
|
response = "";
|
||||||
for(User u:known_users)
|
for(User u:known_users)
|
||||||
{
|
{
|
||||||
response += u.getName() + " ";
|
response += u.getName() + " ";
|
||||||
|
@ -165,7 +167,7 @@ class ConnectionListenerThread extends Thread {
|
||||||
response += s.getInetAddress().getHostAddress() + " ";
|
response += s.getInetAddress().getHostAddress() + " ";
|
||||||
}
|
}
|
||||||
response = response.trim();
|
response = response.trim();
|
||||||
System.out.println("Response :" + response);
|
System.out.println("Response :" + response + "!");
|
||||||
responseBytes = response.getBytes();
|
responseBytes = response.getBytes();
|
||||||
responsePacket = new DatagramPacket(responseBytes, responseBytes.length, clientAddress, 1337);
|
responsePacket = new DatagramPacket(responseBytes, responseBytes.length, clientAddress, 1337);
|
||||||
responseSocket.send(responsePacket);
|
responseSocket.send(responsePacket);
|
||||||
|
@ -388,4 +390,17 @@ public class NetworkClient {
|
||||||
catch(IOException e){}
|
catch(IOException e){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void disconnect()
|
||||||
|
{
|
||||||
|
send(null);
|
||||||
|
for(Socket s:dest_sockets)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
catch(IOException e){}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
載入中…
Reference in a new issue