public String generateHandshake(WebSocketRequest requestInfo) throws UnsupportedEncodingException{
		StringBuilder sb = new StringBuilder();
		if(requestInfo.getSecVersion() < 4){// 版本0--3
		sb.append("HTTP/1.1 101 WebSocket Protocol Handshake").append("\r\n")
		.append("Upgrade: WebSocket").append("\r\n")
		.append("Connection: Upgrade").append("\r\n")
		.append("Sec-WebSocket-Origin: ").append(requestInfo.getOrigin()).append("\r\n")
		.append("Sec-WebSocket-Location: ws://").append(requestInfo.getHost()).append(requestInfo.getRequestUri()).append("\r\n");
		
		if(requestInfo.getCookie() != null){
			sb.append("cookie: ").append(requestInfo.getCookie()).append("\r\n");
		}
		
		sb.append("\r\n"); // 写入空行
		
		sb.append(requestInfo.getDigest());
		//ByteBuffer buffer = ByteBuffer.allocate(sb.length() + requestInfo.getDigest().length); 		
		//buffer.put(sb.toString().getBytes(Utf8Coder.UTF8)).put(requestInfo.getDigest());
		}else{// 大于等于版本4
			sb.append("HTTP/1.1 101 Switching Protocols").append("\r\n")
			.append("Upgrade: websocket").append("\r\n")
			.append("Connection: Upgrade").append("\r\n")
			.append("Sec-WebSocket-Accept: ").append(requestInfo.getDigest()).append("\r\n")
			.append("Sec-WebSocket-Origin: ").append(requestInfo.getOrigin()).append("\r\n")
			.append("Sec-WebSocket-Location: ws://").append(requestInfo.getHost()).append(requestInfo.getRequestUri()).append("\r\n");
			//.append("Sec-WebSocket-Protocol: chat").append("\r\n");
			
			sb.append("\r\n"); // 写入空行			
		}
		log.info("the response: " + sb.toString());
		
		return sb.toString();
	}