-3
inStream = new ObjectInputStream(this.socket.getInputStream());
Packet rank = (Packet)inStream.readObject();

Hi, I supposed to receive an array from two clients. I can only receive from a client and prompt an error like this : Thanks in advance

 java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:209)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2338)
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2351)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2822)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:804)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:301)
    at ServerGraph$Handler.run(ServerGraph.java:350)
user207421
  • 289,834
  • 37
  • 266
  • 440
Anwarul
  • 43
  • 4

1 Answers1

1

I supposed to receive an array from two clients. I can only receive from a client and prompt an error like this

 java.net.SocketException: Connection reset

I think you may be misunderstanding how sockets work. A socket represents a connection between one client and one server. You seem to be saying that that you are expecting to get data from 2 different clients on a single Socket. That is not possible. It doesn't make sense. You need a separate Socket for each client that your server is communicating with.

What you are seeing (the Connection reset) is explicable: the peer (i.e. the client or client's OS), has reset the connection for some reason. The Java (?) client application might called close() or shutdownOutput(), or it might have just exited.

(You haven't shown us enough code to suggest the best way to fix your problem. Are the sockets being opened by the clients or the server?)

Community
  • 1
  • 1
Stephen C
  • 632,615
  • 86
  • 730
  • 1,096