1 Replies - 555 Views - Last Post: 09 December 2012 - 03:33 PM Rate Topic: -----

#1 KeirDavis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-December 12

Java Socket - Connection Reset in Server to Client when Client connect

Posted 09 December 2012 - 02:20 PM

So I'm trying to set up a Client <-> Server connection. I keep getting the most annoying error because the client and server will not connect but only send "cpc" once when I call

print("cpc");

This is the code which I am using. This is contained in a class which extends Thread.

BufferedReader in = null;
out = new PrintWriter(socket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String inputLine, outputLine;
print("cpc");
try{
    while ((inputLine = in.readLine()) != null) {
        outputLine = process(inputLine);
        if (!outputLine.equals("")){
            print(outputLine);
        }

    }
} catch (Exception e){
    e.printStackTrace();
}

There error is where 'while ((inputLine = in.readLine()) != null) {' is located.

Here is the error if any of you need it.

Quote

java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at javaclient.Client.run(Client.java:28)

Heres the print() code

public void print(String s){
    out.println(s);
}


Is This A Good Question/Topic? 0
  • +

Replies To: Java Socket - Connection Reset in Server to Client when Client connect

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3464
  • View blog
  • Posts: 15,676
  • Joined: 20-September 08

Re: Java Socket - Connection Reset in Server to Client when Client connect

Posted 09 December 2012 - 03:33 PM

Looks like the other end has disconnected
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1