title: java.net.SocketException: connection reset on reading bytes
body: <p>i am trying to create a little server in java using sockets.
  The sockets are connected but when i send data from my client to my server it gives an exception. </p>
  
  <p>stacktrace (UPDATED):</p>
  
  <pre><code>    IOException on socket listen: java.net.SocketException: Connection reset
      java.net.SocketException: Connection reset
      at java.net.SocketInputStream.read(Unknown Source)
      at java.io.ObjectInputStream$PeekInputStream.read(Unknown Source)
      at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
      at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
      at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
      at java.io.ObjectInputStream.&lt;init&gt;(Unknown Source)
      at org.codox.game.network.NetworkController$doComms.run(NetworkController.java:81)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>if you need more information tell me</p>
  
  <p>any suggestions are welcome</p>
  
  <p>thx</p>
  
  <p>-- EDITED --</p>
  
  <p>full server code:</p>
  
  <pre><code>class doComms implements Runnable
  {
      private Socket server;
      PackageHandler packageHandler;
      doComms(Socket server)
      {
          this.server = server;
          packageHandler = new PackageHandler();
      }
  
      public void run()
      {
  
          try
          {
              ObjectInputStream ois = new ObjectInputStream(server.getInputStream());     
              ClientPackage clientPack = (ClientPackage) ois.readObject();
  
              RespondPackage rp = packageHandler.handlePackage(clientPack);
  
              ObjectOutputStream ous = new ObjectOutputStream(server.getOutputStream());
  
              ous.writeObject(rp);
              ous.flush();
  
              server.close();
              System.out.println("Connection was finished and closed.");
  
          } catch (ClassNotFoundException e)
          {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IOException ioe)
          {
              System.out.println("IOException on socket listen: " + ioe);
              ioe.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>full client code:</p>
  
  <pre><code>SocketHints hints = new SocketHints();
          hints.keepAlive = true;
          hints.connectTimeout = 2000;
  
          Socket socket;
          try
          {
              socket = Gdx.net.newClientSocket(Protocol.TCP, "127.0.0.1", 12346, hints);
  
              ClientPackage client = new ClientPackage();
              client.setRequestType(RequestType.ping);
  
              ObjectOutputStream ous = new ObjectOutputStream(socket.getOutputStream());
  
              ous.writeObject(client);
              ous.flush();
  
              ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
  
              RespondPackage response = (RespondPackage) ois.readObject();
              System.out.println("Respone type = " + response.getRequestType());
  
          } catch (UnknownHostException e1)
          {
              // TODO Auto-generated catch block
              e1.printStackTrace();
          } catch (IOException e1)
          {
              // TODO Auto-generated catch block
              e1.printStackTrace();
          } catch (Exception e)
          {
  
          }
  </code></pre>