@Override
    public void run() {
        //Basic packetloss check
        int packetsLost = 0;
        while(true) {
            if(packetsLost<11) {
                try {
                    Object o = in.readObject();
                    if(o instanceof String) {
//                        System.out.println("Got string from server: "+o);
                        me.messages.add((String)o);
                    }
                    else if(o instanceof Message_Heartbeat) {
                        Message_Heartbeat m_h = (Message_Heartbeat) o;
                        System.out.println("Heartbeat from server! T:"+m_h.read());
                    }
//                    System.out.println("Listening for objects from server...");
                    //We got that packet, reset the counter.
                    packetsLost=0;

                } catch (Exception ex) {
                    System.err.println("Failed to read object from server! Treat it as packet loss. "+ex.getMessage());
                    packetsLost++;
                }
            } else {
                try {
                    //10 packets in a row! We probably disconnected
                    me.getSocket().close();
                } catch (IOException ex) {
                    System.err.println("Failed to close the socket, shutting down any way.");
                }
                //Break it even if we fail to close the socket properly
                System.exit(0);
            }
        }
    }