Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.net.SocketException: socket closed TCP Client Server Communication [duplicate]

I am creating a java client/server application over TCP where we have two sockets:

  • One is for exchanging messages.
  • Two is for file transfer.

I have created in the Server two ServerSockets in order to create Socket One and Two
by accepting the ServerSockets.

At first the client sends some bytes through the first Socket
so that it can tell the Server which file it needs.

Then the Server through the second socket sends the file to the client.
After the client receives the file tries to send back to the server a Transfer Done Message.

There I get the Exception for the closed socket.
However I never close the socket up until now.
I only close the buffer which sents the file.
Even if I try to open again the socketInputStream after I sent the file the error is still the same.
Also if I do not close the buffer which sents the file, the client does not get the file.

Server Exception

Error in Return Message - java.net.SocketException: socket closed

Client Exception

Server response - java.net.SocketException: Software caused connection abort: socket write error

What am I doing wrong?

like image 865
lemanou Avatar asked Apr 02 '13 16:04

lemanou


People also ask

How do you handle socket exception in Java?

The SocketException is an exception in Java that is thrown to indicate that an error was encountered while creating or accessing a Socket. Since the SocketException is a checked exception, it either needs to be thrown or surrounded by a try-catch block in code.

Why do we get Java net SocketException connection reset?

java.net.SocketException: Connection reset This SocketException occurs on the server-side when the client closed the socket connection before the response could be returned over the socket. For example, by quitting the browser before the response was retrieved. Connection reset simply means that a TCP RST was received.

What is the cause of connection reset?

Summary. If you run into the “ERR_CONNECTION_RESET” error, it means that your browser can't establish a connection to the remote server. In most cases, it's due to a misconfiguration in your internet settings or something else that's blocking the connection.


1 Answers

A 'Socket closed' exception means that the application that caught the exception closed the socket and then kept trying to use it. You may be unaware that closing the input or output stream of a socket closes the other stream and the socket as well. For 'software caused connection abort' see the duplicate link.

like image 142
user207421 Avatar answered Oct 25 '22 11:10

user207421