我正在使用这段代码,它使用套接字公开一个简单的函数:
while (true) {
try {
ServerSocket serverSocket = new ServerSocket(7070);
Socket clientSocket = serverSocket.accept();
String input = (new BufferedReader(new InputStreamReader(clientSocket.getInputStream()))).readLine();
synchronized (this.map) {
ObjectOutputStream o = new ObjectOutputStream(clientSocket.getOutputStream());
o.writeChars(map.get(input));
o.close();
}
clientSocket.close();
serverSocket.close();
} catch(Exception e) {
e.printStackTrace();
}
}
我究竟做错了什么?日志显示它卡在输入接收线中,有时会抛出异常,说明套接字正在使用中