private void writeMessage() throws Exception {
		if (!this.writeQueue.isEmpty()) {
			CoreMessage message = writeQueue.poll();
			this.writeBuffer.clear();
			this.messageCodecHandler.encodeMessage(this.writeBuffer, message);
			if (message.getType() == CoreMessageType.KEEP_ALIVE_MESSAGE) {
				this.lastKeepAliveTime = System.currentTimeMillis();
			} else {
				if (message.getType() == CoreMessageType.USER_MESSAGE) {
					if (GlobalUtil.SHOW_SYSTEM_OUT)
						System.out.println(Thread.currentThread().getId() + " Encoded message " + message.getType().toString() + " type int: " + ((UserMessage) message.getMessageData()).messageType);
				} else {
					if (GlobalUtil.SHOW_SYSTEM_OUT)
						System.out.println(Thread.currentThread().getId() + " Encoded message " + message.getType().toString());
				}
				if (message.getType() == CoreMessageType.SEND_FILE_INFO || message.getType() == CoreMessageType.CANCEL_RECEIVING_FILE) {
					this.isWaitingRemote = true;
				}
			}
		}
		while (this.writeBuffer.remaining() > 0) {
			int writeCount = this.socketChannel.write(this.writeBuffer);
			if (GlobalUtil.SHOW_SYSTEM_OUT)
				System.out.println(Thread.currentThread().getId() + " Write " + writeCount + " bytes to socketChannel, buffer remaining: " + this.writeBuffer.remaining());
		}
	}