服务器使用线程接受多个连接。
服务器:
@Override
public void run () {
try {
System.out.println(client);
System.out.println("Client Connected");
//So far, so good. Client is connected
BufferedReader in = new BufferedReader(
new InputStreamReader(this.client.getInputStream()));
System.out.println(in.readLine());
// Nothing happens
} catch (Exception e) {
e.printStackTrace();
}
}
客户端:
try {
PrintWriter out = new PrintWriter(Client.socket.getOutputStream());
BufferedReader in = new BufferedReader (
new InputStreamReader(Client.socket.getInputStream()));
out.write("Information sent from client");
// Does not work
in.read();
// Before this .read it would give a "Connection reset" probably
// Because the client closed before the server could even read
}
没有错误,但它只是挂起,没有发送任何内容。防火墙已经关闭,所以不可能。它曾经在昨天工作。我不知道我可能搞砸了什么。