• 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 ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • 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

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

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)
Posts: 9509
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!