title: Why am I getting "java.net.SocketExcpecption: Connection reset"?
body: <p>I'm trying to write a tcp client and server program. The server's working just fine, it's opening the socket normally, but when I run the client program, i get the following error:</p>
  
  <pre><code>Exception in thread "main" java.net.SocketException: Connection reset
      at java.net.SocketInputStream.read(Unknown Source)
      at java.net.SocketInputStream.read(Unknown Source)
      at server.Client.main(Client.java:22)
  </code></pre>
  
  <p>Can anyone tell me how I fix it? Thanks in advance</p>
  
  <p>Here is my client code</p>
  
  <pre><code>public class Client {
  
  private final static String serverIP = "192.168.56.1";
  private final static int serverPort = 50000;
  private final static String fileOutput ="D:\\Julian\\Kancolle.7z";
  
  public static void main(String args[]) throws UnknownHostException, IOException {
      Socket sock = new Socket(serverIP, serverPort);
      byte[] byte_arr = new byte[1024];
      InputStream is = sock.getInputStream();
      FileOutputStream fos = new FileOutputStream(fileOutput);
      BufferedOutputStream bos = new BufferedOutputStream(fos);
      int bytesRead = is.read(byte_arr, 0, byte_arr.length);
      bos.write(byte_arr, 0, bytesRead);
      bos.close();
      sock.close();
    }
  }
  </code></pre>
  
  <p>and server code </p>
  
  <pre><code>public class Server implements Runnable {
  
  private final static int serverPort = 50000;                        // reserves port
  private final static String fileInput = "D:\\Julian\\Kancolle";     // destination
  
  public static void main(String args[]) throws IOException{
  
      int bytesRead; // buffer variable
  
      ServerSocket servsock = new ServerSocket(serverPort);
      File myFile = new File(fileInput);
      while (true) {
        Socket sock = servsock.accept();
  
        InputStream in = sock.getInputStream();
        OutputStream output = new FileOutputStream(myFile);
        byte[] buffer = new byte[1024]; // buffer
  
        while((bytesRead = in.read(buffer)) != -1)
        {
            output.write(buffer,  0,  bytesRead);;
        }
        output.close();
        servsock.close();
      }
  }
  
  public static void start(){
      Server upd = new Server();  
      Thread tupd = new Thread(upd);  
      tupd.start(); 
  }
  
  @Override
  public void run() {
  
  }
  }
  </code></pre>