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)