file_websocket_basic_wsh.py (851B)
1 from mod_pywebsocket import msgutil 2 3 4 def web_socket_do_extra_handshake(request): 5 # must set request.ws_protocol to the selected version from ws_requested_protocols 6 request.ws_protocol = request.ws_requested_protocols[0] 7 8 if request.ws_protocol == "error": 9 raise ValueError("Error") 10 pass 11 12 13 def web_socket_transfer_data(request): 14 while True: 15 line = msgutil.receive_message(request) 16 if line == "protocol": 17 msgutil.send_message(request, request.ws_protocol) 18 continue 19 20 if line == "resource": 21 msgutil.send_message(request, request.ws_resource) 22 continue 23 24 if line == "origin": 25 msgutil.send_message(request, request.ws_origin) 26 continue 27 28 msgutil.send_message(request, line) 29 30 if line == "end": 31 return