public Packet read() {
		try {
			ByteBuffer header = ByteBuffer.allocate(4);
			int code = socket.read(header);
			if (code == 4) {
				header.flip();
				short id = header.getShort();
				short len = header.getShort();
				ByteBuffer data = ByteBuffer.allocate(len);
				socket.read(data);
				data.flip();
				Packet packet = PacketCodecs.CLIENT_SERVER.read(id, data);
				if (packet != null) {
					return packet;
				} else {
					System.out.println("[Server] failed to read full packet");
				}
			} else if (code >= 0) {
				System.out.println("[Server] Malformed data received from " + socket.getRemoteAddress());
			}
		} catch (IOException e) {
			System.err.println("Failed to read from " + getRemoteAddress() + ": " + e.getMessage());
			try {
				socket.close();
			} catch (IOException e1) {
				System.err.println("Failed to close socket from " + getRemoteAddress() + ": " + e1.getMessage());
			}
		}
		return null;
	}