private void handleSelectionKey(SelectionKey key) throws IOException {
		if ((key.readyOps() & SelectionKey.OP_CONNECT) == SelectionKey.OP_CONNECT) {
			boolean ok = channel.finishConnect();
			System.out.println("[Client] Finished connecting to " + channel.getRemoteAddress() + (ok ? " successfully" : " failure"));
			channel.register(selector, SelectionKey.OP_READ);
			session = new ClientSession(this);
			ConnectPacket connectPacket = new ConnectPacket();
			connectPacket.name = name;
			send(connectPacket);
		} else if ((key.readyOps() & SelectionKey.OP_READ) == SelectionKey.OP_READ) {
			SocketChannel sc = (SocketChannel) key.channel();
			ByteBuffer header = ByteBuffer.allocate(4);
			int code = sc.read(header);
			if (code == 4) {
				header.flip();
				short id = header.getShort();
				short len = header.getShort();
				//System.out.println("Id=" + id + ", Len=" + len);
				ByteBuffer data = ByteBuffer.allocate(len);
				sc.read(data);
				data.flip();
				//System.out.println(PacketCodecs.bytesToHex(data.array()));
				Packet packet = PacketCodecs.SERVER_CLIENT.read(id, data);
				if (packet != null) {
					System.out.println("[Client] Received data on " + channel.getRemoteAddress() + ": " + packet.toString());
					session.handle(sc, packet);
				} else {
					System.out.println("[Client] failed to read full packet");
				}
			} else {
				System.out.println("[Client] Server disconnected");
				channel.close();
			}
		}
	}