• Post Reply Bookmark Topic Watch Topic
  • New Topic

Connection reset error in input.readLine()

 
Sam Gehouse
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)
 
Joe Ess
Bartender
Posts: 9362
11
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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!