File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes get Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "get "java.net.SocketException: socket closed", even if i am using HTTP connection" Watch "get "java.net.SocketException: socket closed", even if i am using HTTP connection" New topic
Author

get "java.net.SocketException: socket closed", even if i am using HTTP connection

Dupont Girard
Greenhorn

Joined: Mar 21, 2011
Posts: 24
Hi, I encountered an exception by executing this code:





The line of code that make this exception is: "int taille = input.read(mot);", if i copy it into the Servlet part, it works well, but i think that the Servlet shall not be in charge of these.

The exception is:
"java.net.SocketException: socket closed" even if i am not using Sockets, but HTTP.
I think that the "input" in RequestStatement's method contains no value "null"

Help me



Chris Beckey
Ranch Hand

Joined: Jun 09, 2006
Posts: 116

I believe that what is happening is that the RequestStatement thread is not finishing by the time the HTTP thread, which the servlet code is running on is finishing and closing the connection.
In this case I don't see a reason to start the second thread because you would have to synchronize and wait for it to complete before returning from the servlets doXXX method anyway. It will also complicate error handling, redirection and including content should that ever become necessary.
Dupont Girard
Greenhorn

Joined: Mar 21, 2011
Posts: 24
Thanks Chris of your answer. You're right, i just put a join() on my thread and it works
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: get "java.net.SocketException: socket closed", even if i am using HTTP connection
 
Similar Threads
Sending a file over socket
Error in calling shutDownInput and shutDownOutput
Problem in wrtitng JAR File
Not Sure
Creating a Pipe that connects 2 sockets