I am making an application that accepts a TCP Socket connection and displays the info it sends. This works. I have decided though that i want to be able to send information multiple times from the client to the server. Right now this is how it sends.
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());
}
}
I get this error:
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)
Don’t close the socket in
sendData. You will need to handle closing in code outsidesendData.EDIT: This exception can be caused when the remote side terminates the connection. What is likely happening is that your use of two
ObjectOutputStreams is causing an exception at the server, which is forcibly terminating the connection.