• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Connection reset error in input.readLine()  RSS feed

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting connection reset exception in line input.readLine() as shown below. Any help will be appreciated.

Code is shown below

Socket socket = new Socket();
socket.connect(new InetSocketAddress("myMachine", 4444), 0);

DataOutputStream output = new DataOutputStream(outputStream);
DataInputStream input = new DataInputStream(socket.getInputStream());
String request = "abcd" // abcd is the string passed to server
output.write(request.getBytes());

String responseLine;
while (true) {
responseLine = input.readLine();
os.println(responseLine);
}

On input.readLine() I get the exception as shown below:

java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:136)
at java.net.SocketInputStream.read(SocketInputStream.java:208)
at java.io.DataInputStream.readLine(DataInputStream.java:527)
 
Bartender
Posts: 9509
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are only showing us half the picture, but does your server code happen to close the socket (rather than the input stream) when it is done reading the request?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!