content/base/test/file_websocket_basic_wsh.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/file_websocket_basic_wsh.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,29 @@
     1.4 +from mod_pywebsocket import msgutil
     1.5 +
     1.6 +def web_socket_do_extra_handshake(request):
     1.7 +  # must set request.ws_protocol to the selected version from ws_requested_protocols
     1.8 +  request.ws_protocol = request.ws_requested_protocols[0]
     1.9 +
    1.10 +  if (request.ws_protocol == 'error'):
    1.11 +      raise ValueError('Error')
    1.12 +  pass
    1.13 +
    1.14 +def web_socket_transfer_data(request):
    1.15 +  while True:
    1.16 +    line = msgutil.receive_message(request)
    1.17 +    if line == 'protocol':
    1.18 +      msgutil.send_message(request, request.ws_protocol)
    1.19 +      continue
    1.20 +
    1.21 +    if line == 'resource':
    1.22 +      msgutil.send_message(request, request.ws_resource)
    1.23 +      continue
    1.24 +
    1.25 +    if line == 'origin':
    1.26 +      msgutil.send_message(request, request.ws_origin)
    1.27 +      continue
    1.28 +
    1.29 +    msgutil.send_message(request, line)
    1.30 +
    1.31 +    if line == 'end':
    1.32 +      return

mercurial