我正在制作一个接受 TCP 套接字连接并显示它发送的信息的应用程序。这行得通。我已经决定我希望能够多次从客户端向服务器发送信息。现在这就是它的发送方式。
socketStream = socket.getOutputStream();
to_send.add(new String[][] {{
ips + ":" + socket.getPort(),
System.getProperty("user.name"),
System.getProperty("os.name")
}});
sendData(to_send);
while(!finished) {
socketStream = socket.getOutputStream();
oos = new ObjectOutputStream(socketStream);
oos.writeObject(new String[][] {{"Open","LOL"}});
oos.flush();
}
-
public void sendData(ArrayList<String[][]> d) {
try {
oos = new ObjectOutputStream(socketStream);
oos.writeObject(d);
oos.flush();
System.out.println("Sent: " + to_send.get(0));
} catch (Exception e) {
System.out.println(e.toString());
}
}
我收到此错误:
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(Unknown Source)
at java.io.ObjectOutputStream.writeNonProxyDesc(Unknown Source)
at java.io.ObjectOutputStream.writeClassDesc(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeFatalException(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at Server.<init>(Server.java:57)
at Server.main(Server.java:26)