public void service() throws IOException {
		//由serverSocketChannel向selector注册接受连接就绪事件，如果就绪，则将SelectionKey对象加入到Selected-keys集合中
		serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
		while(selector.select()>0){
			Set readyKeys = selector.selectedKeys();
			Iterator it = readyKeys.iterator();
			while (it.hasNext()) {
				SelectionKey selectionKey = null;
				selectionKey = (SelectionKey) it.next();
				it.remove();
				if (selectionKey.isAcceptable()){
					
				}
				if (selectionKey.isReadable()){
					
				}
				if(selectionKey.isWritable()){
					ByteBuffer bf = (ByteBuffer) selectionKey.attachment();
					SocketChannel sc = (SocketChannel) selectionKey.channel();
					bf.flip();  //将position位置设置为0
					CharBuffer cb = charSet.decode(bf);
					String data = cb.toString();
					if (data.indexOf("\r\n")==-1) return;
					String outputData = data.substring(0,data.indexOf("\n")+1);
					ByteBuffer outputBuffer = charSet.encode("echo"+outputData);
					while(outputBuffer.hasRemaining()){
						sc.write(outputBuffer);
					}
					
					ByteBuffer temp = charSet.encode(outputData);
					bf.position(temp.limit());
					bf.compact(); //删除已经处理的字符串
					
					if (outputData.equals("bye\r\n")){
						selectionKey.cancel();
						sc.close();
						System.out.println("关闭与客户端的连接");
					}
				}
			}
		}
	}