public boolean write() throws IOException {
		SelectionKey key = this.channel.keyFor(this.nioEngineImp.getSelector());
		
		if(currentStateWrite == WRITING_DONE){	
			if(listBuffer.size() > 0){
				bufferWrite = listBuffer.get(0);
				listBuffer.remove(0);
				bufferWrite.position(0);
				lengthBufferWrite.position(0);
				lengthBufferWrite.putInt(bufferWrite.capacity());
				lengthBufferWrite.position(0);
				currentStateWrite = WRITING_LENGTH;
			}
		}


		if(currentStateWrite == WRITING_LENGTH){

			try{
				channel.write(lengthBufferWrite);
			}catch(IOException e){
				key.cancel();
				channel.close(); 
			}

			if(lengthBufferWrite.remaining() == 0){
				currentStateWrite = WRITING_MSG;
			}

		} if(currentStateWrite == WRITING_MSG){

			if(bufferWrite.remaining() > 0){

				try{
					channel.write(bufferWrite);
				}catch(IOException e){
					key.cancel(); 
					channel.close(); 
				}
			}

			if(bufferWrite.remaining() == 0){
				currentStateWrite = WRITING_DONE;
			}

		}
		return (listBuffer.size() == 0);
	}