Connection reset by peer: socket write error While tring to send object
<p>So I'm getting Connection reset by peer: socket write error while tring to send object and I don't know why. This is small part of my university project, I have spent a lot of time tring to make it work but I'm really out of ideas. I would be really greatful for your help.
I tried to send a simple string message to client and it works fine.</p>

<p>Server code:     </p>

<pre><code>public class Server {
static ServerSocket serverSocket;

public static void main(String args[]) {
    try {
    serverSocket = new ServerSocket(7777);
    Map map = new Map();
    while(true)
    {
        Socket incoming  = serverSocket.accept();
        System.out.println(incoming.toString());
        Runnable r = new ServerConnection(incoming, map);
        Thread t = new Thread(r);
        t.start();
    }       
  }
}
</code></pre>

<p>ServerConnection code:</p>

<pre><code>public class ServerConnection implements Runnable {
private Socket s;
private ObjectOutputStream out;
private Map map;
public ServerConnection(Socket out, Map map){
    this.s = out;
    this.map = map;
    System.out.println(map);
}

public void sendMap(){
    //map.setRotation(rotated);
    try {
        out = new ObjectOutputStream(s.getOutputStream());
        System.out.println(out);
        System.out.println(this.map);
        out.writeObject(this.map);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

public void closeSocket(){
    try {
        s.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

@Override
public void run() {
    //this.connect();
    this.sendMap();
}
}
</code></pre>

<p>The print stacktrace gives this information : </p>

<pre><code>java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(Unknown Source)`
at java.io.ObjectOutputStream.writeFatalException(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at Server.ServerConnection.sendMap(ServerConnection.java:39)
at Server.ServerConnection.run(ServerConnection.java:59)
at java.lang.Thread.run(Unknown Source)
</code></pre>

<p>Yes, I checked if Map is not null and if output exists etc. I don't know what triggers the problem.</p>

<p>Edit: - Object Map is serializable.</p>

<p>Client Console output:</p>

<pre><code>Exception in thread "main" java.lang.NullPointerException
    at Client.ClientConnection.getMap(ClientConnection.java:37)
    at Client.Client.main(Client.java:28)
</code></pre>

<p>Client code: </p>

<pre><code>public static void main(String[] args) {
    ClientConnection c = new ClientConnection();
    c.connect();
    Map map = c.getMap();
    System.out.println(map);
    c.closeSocket();
}
</code></pre>

<p>ClientConnection: - serverString is local adres "127.0.0.1"</p>

<pre><code>public void connect(){
        try
        {
            Socket s = new Socket(serverString,7777);
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   
    }

    public Map getMap(){
    Map map;
    try {
        input = new ObjectInputStream(s.getInputStream());
        map = (Map)(input.readObject());
        return map;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
    }
public void closeSocket(){
        try {
            s.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
</code></pre>