0

I'm trying to send a String data over TCP using ObjectOutputStream, but I always get "java.net.SocketException: Connection reset". Here is my code:

Client:

clientSocket = new Socket("127.0.0.1", 9000);
oo = new ObjectOutputStream(clientSocket.getOutputStream());
oo.writeObject(data);
oo.flush();

Server:

    ServerSocket server = new ServerSocket(9000);
    Socket client = server.accept();
    ObjectInputStream oi = new ObjectInputStream(client.getInputStream());
    String data = (String) oi.readObject();
    System.out.println(data);
  • Connection reset at the client end? What happens on the server end at that point? I can't see anything obvious you're doing wrong, but it might be worth e.g. testing this sending strings through to check the network part is OK. – Rup Mar 21 '18 at 23:42
  • Possible duplicate of [What's causing my java.net.SocketException: Connection reset?](https://stackoverflow.com/questions/585599/whats-causing-my-java-net-socketexception-connection-reset) – Raedwald Nov 13 '18 at 22:24

0 Answers0