public synchronized void write() {
		if (_outData.size() == 0) {
			// if nothing left in the output string, go back to read mode
			switchToReadOnlyMode();
			return;
		}
		// if there is something to send
		ByteBuffer buf = _outData.remove(0);
		if (buf.remaining() != 0) {
			try {
				_sChannel.write(buf);
			} catch (IOException e) {
				// this should never happen.
				e.printStackTrace();
			}
			// check if the buffer contains more data
			if (buf.remaining() != 0) {
				_outData.add(0, buf);
			}
		}
		// check if the protocol indicated close.
		if (_protocol.shouldClose()) {
			switchToWriteOnlyMode();
			if (buf.remaining() == 0) {
				closeConnection();
				SocketAddress address = _sChannel.socket().getRemoteSocketAddress();
				logger.info("disconnecting client on " + address);
			}
		}
	}