title: Java socket sends some data during connection to server 2
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/8219559/java-socket-sends-some-data-during-connection-to-server">Java socket sends some data during connection to server</a>  </p>
  </blockquote>
  
  
  
  <p>I have two very very simple java programs - client and server.They establish connection through sockets.
  Server reads characters from stream and prints them to console.</p>
  
  <pre><code>import java.net.*;
  import java.io.*;
  import java.util.Date;
  public class DataServerSIMS {
      static final int LISTENING_PORT = 2002;
      public static void main(String[] args) {
          ServerSocket listener;  //Checks the connection requests
          Socket connection;      //To interact with other progs
          Reader incoming;            //Stream
          try {
              listener = new ServerSocket(LISTENING_PORT);
              TextIO.putln("Listening on port "+LISTENING_PORT);
              while (true) {
                  connection = listener.accept();
                  try {
                      incoming = new InputStreamReader(connection.getInputStream());
                      while (true) {
                          int ch = incoming.read();
                          if (ch == 1 || ch == '\r')
                              break;
                              System.out.print((char)ch);
                      }
                      System.out.println();
                      incoming.close();
                  }
                  catch (IOException e) {
                      TextIO.putln("Error: "+e);
                  }//end try recieving data
              }//end while
          }
          catch (Exception e) {
              TextIO.putln("Sorry, the server has shut down.");
              TextIO.putln("Error: "+e);
              return;
          }
      }
  }
  </code></pre>
  
  <p>Client only establishes socket-connection.</p>
  
  <pre><code>import java.net.*;
  import java.io.*;
  import java.util.Date;
  public class TempClientSIMS {
      //static final int LISTENING_PORT = 32007;
      static final int LISTENING_PORT = 2002;
      public static void main(String[] args) {
          ServerSocket listener;  //Checsk the connection requests
          Socket connection;      //To interact with other progs
          Socket connectionToServer = null;   //Socket
          Reader incoming;            //Stream
          try {
  
              TextIO.putln("Localhost connects to:"+LISTENING_PORT);
  
              connectionToServer = new Socket ("localhost", 2002);
  
              TextIO.putln("Connected ");
  
              long i=0;
              while (i&lt;2000000000) {
                  i++;
              }
  
  
          }
          catch (Exception e) {
              TextIO.putln("Sorry, the server has shut down.");
              TextIO.putln("Error: "+e);
              return;
          }
      }
  
  
  }
  </code></pre>
  
  <p><strong>Client doesn't send any data to server.</strong></p>
  
  <p>I launched both programs on my PC.
  Client printed:</p>
  
  <pre><code>Localhost connects to:2002
  Connected
  Press any key to continue . . .
  </code></pre>
  
  <p>Server printed:</p>
  
  <pre><code>Listening on port 2002
  FdsfsdfsError: java.net.SocketException: Connection reset
  </code></pre>
  
  <p>It is clear why this string "<code>Error: java.net.SocketException: Connection reset</code>" is printed on server's console.
  But I haven't any idea what does it mean: "<code>Fdsfsdfs</code>"?
  And can I prevent the printing of this string "<code>Fdsfsdfs</code>"?</p>