Socket.read/write partially working