我正在尝试使用ObjectOutputStream通过TCP发送字符串数据,但我总是得到“java.net.SocketException:Connection reset”。这是我的代码:
客户端:
clientSocket = new Socket("127.0.0.1", 9000);
oo = new ObjectOutputStream(clientSocket.getOutputStream());
oo.writeObject(data);
oo.flush();
服务器:
ServerSocket server = new ServerSocket(9000);
Socket client = server.accept();
ObjectInputStream oi = new ObjectInputStream(client.getInputStream());
String data = (String) oi.readObject();
System.out.println(data);