public void write( SelectionKey key ) throws IOException {
		
		SocketChannel chan = (SocketChannel) key.channel();
		TcpConnection tcp = getConnection(key);
		
		ByteBuffer buf = null;
		
		// find something to write
		while( tcp.hasWrite() ){
			buf = tcp.fetchWrite();
			if( buf != null && buf.hasRemaining() ){
				break;
			}
		}
		
		if( buf != null ){
					
			if( ! buf.isReadOnly() ){
				logger.debug("Writing to {}. Data {}", chan.getRemoteAddress(), buf.array() );
			}else{
				logger.debug("Writing to {}", chan.getRemoteAddress() );
			}
			
			chan.write( buf );
		}
	}