title: Java server socket connection reset
body: <p>When my <strong><em>SECOND</em></strong> client connect to my server I got this error:</p>
  
  <pre><code>Exception in thread "main" java.net.SocketException: Connection reset
      at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)
      at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
      at java.base/java.net.SocketInputStream.read(SocketInputStream.java:200)
      at java.base/java.io.DataInputStream.readLine(DataInputStream.java:518)
      at Main.main(Main.java:24)
  </code></pre>
  
  <p>I don't know what am I doing wrong.</p>
  
  <p><strong><em>FIRST</em></strong> client works normal</p>
  
  <p>My code:</p>
  
  <pre><code>import java.io.*;
  import java.net.ServerSocket;
  import java.net.Socket;
  import java.util.Date;
  
  public class Main {
      public static void main(String[] args) throws IOException {
           ServerSocket serverSocket = new ServerSocket(50505);;
           Socket socket;
           while (true) {
               socket = serverSocket.accept();
               while(socket.isConnected()) {
                   String v;
                   DataInputStream in;
                   InputStream in_sock;
                   in_sock = socket.getInputStream();
                   in = new DataInputStream(in_sock);
                   v = in.readLine();
                   System.out.println(v);
                   OutputStream output = socket.getOutputStream();
                   DataOutputStream out = new DataOutputStream(output);
                   out.writeChars("123\n");
                   out.writeChars("123\n");
                   out.writeChars("123\n");
               }
           }
      }
  }
  </code></pre>
  
  <p>PS: How can I share error on stackoverflow?  like code?</p>