当前位置: 首页>>代码示例>>Python>>正文


Python msgutil.receive_message函数代码示例

本文整理汇总了Python中mod_pywebsocket.msgutil.receive_message函数的典型用法代码示例。如果您正苦于以下问题:Python receive_message函数的具体用法?Python receive_message怎么用?Python receive_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了receive_message函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_receive_message_deflate_frame_client_using_smaller_window

    def test_receive_message_deflate_frame_client_using_smaller_window(self):
        """Test that frames coming from a client which is using smaller window
        size that the server are correctly received.
        """

        # Using the smallest window bits of 8 for generating input frames.
        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -8)

        data = ''

        # Use a frame whose content is bigger than the clients' DEFLATE window
        # size before compression. The content mainly consists of 'a' but
        # repetition of 'b' is put at the head and tail so that if the window
        # size is big, the head is back-referenced but if small, not.
        payload = 'b' * 64 + 'a' * 1024 + 'b' * 64
        compressed_hello = compress.compress(payload)
        compressed_hello += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_hello = compressed_hello[:-4]
        data += '\xc1%c' % (len(compressed_hello) | 0x80)
        data += _mask_hybi(compressed_hello)

        # Close frame
        data += '\x88\x8a' + _mask_hybi(struct.pack('!H', 1000) + 'Good bye')

        extension = common.ExtensionParameter(common.DEFLATE_FRAME_EXTENSION)
        request = _create_request_from_rawdata(
            data, deflate_frame_request=extension)
        self.assertEqual(payload, msgutil.receive_message(request))

        self.assertEqual(None, msgutil.receive_message(request))
开发者ID:cscheid,项目名称:forte,代码行数:31,代码来源:test_msgutil.py

示例2: test_receive_message_permessage_deflate_compression

    def test_receive_message_permessage_deflate_compression(self):
        compress = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        data = ""

        compressed_hello = compress.compress("HelloWebSocket")
        compressed_hello += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_hello = compressed_hello[:-4]
        split_position = len(compressed_hello) / 2
        data += "\x41%c" % (split_position | 0x80)
        data += _mask_hybi(compressed_hello[:split_position])

        data += "\x80%c" % ((len(compressed_hello) - split_position) | 0x80)
        data += _mask_hybi(compressed_hello[split_position:])

        compress = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        compressed_world = compress.compress("World")
        compressed_world += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_world = compressed_world[:-4]
        data += "\xc1%c" % (len(compressed_world) | 0x80)
        data += _mask_hybi(compressed_world)

        # Close frame
        data += "\x88\x8a" + _mask_hybi(struct.pack("!H", 1000) + "Good bye")

        extension = common.ExtensionParameter(common.PERMESSAGE_COMPRESSION_EXTENSION)
        extension.add_parameter("method", "deflate")
        request = _create_request_from_rawdata(data, permessage_compression_request=extension)
        self.assertEqual("HelloWebSocket", msgutil.receive_message(request))
        self.assertEqual("World", msgutil.receive_message(request))

        self.assertEqual(None, msgutil.receive_message(request))
开发者ID:hinike,项目名称:opera,代码行数:33,代码来源:test_msgutil.py

示例3: web_socket_transfer_data

def web_socket_transfer_data(request):
    global connections
    r = request.ws_resource.split('?', 1)
    if len(r) == 1:
        return
    param = cgi.parse_qs(r[1])
    if 'p' not in param:
        return
    page_group = param['p'][0]
    if page_group in connections:
        connections[page_group].add(request)
    else:
        connections[page_group] = set([request])
    message = None
    dataToBroadcast = {}
    try:
        message = msgutil.receive_message(request)
        # notify to client that message is received by server.
        msgutil.send_message(request, message)
        msgutil.receive_message(request)
        dataToBroadcast['message'] = message
        dataToBroadcast['closeCode'] = str(request.ws_close_code)
    finally:
        # request is closed. notify this dataToBroadcast to other WebSockets.
        connections[page_group].remove(request)
        for ws in connections[page_group]:
            msgutil.send_message(ws, json.dumps(dataToBroadcast))
开发者ID:335969568,项目名称:Blink-1,代码行数:27,代码来源:close-on-unload_wsh.py

示例4: test_receive_message_deflate_frame

    def test_receive_message_deflate_frame(self):
        compress = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        data = ""

        compressed_hello = compress.compress("Hello")
        compressed_hello += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_hello = compressed_hello[:-4]
        data += "\xc1%c" % (len(compressed_hello) | 0x80)
        data += _mask_hybi(compressed_hello)

        compressed_websocket = compress.compress("WebSocket")
        compressed_websocket += compress.flush(zlib.Z_FINISH)
        compressed_websocket += "\x00"
        data += "\xc1%c" % (len(compressed_websocket) | 0x80)
        data += _mask_hybi(compressed_websocket)

        compress = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        compressed_world = compress.compress("World")
        compressed_world += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_world = compressed_world[:-4]
        data += "\xc1%c" % (len(compressed_world) | 0x80)
        data += _mask_hybi(compressed_world)

        # Close frame
        data += "\x88\x8a" + _mask_hybi(struct.pack("!H", 1000) + "Good bye")

        extension = common.ExtensionParameter(common.DEFLATE_FRAME_EXTENSION)
        request = _create_request_from_rawdata(data, deflate_frame_request=extension)
        self.assertEqual("Hello", msgutil.receive_message(request))
        self.assertEqual("WebSocket", msgutil.receive_message(request))
        self.assertEqual("World", msgutil.receive_message(request))

        self.assertEqual(None, msgutil.receive_message(request))
开发者ID:hinike,项目名称:opera,代码行数:35,代码来源:test_msgutil.py

示例5: web_socket_transfer_data

def web_socket_transfer_data(request):
  if request.ws_protocol == "test 2.1" or request.ws_protocol == "test 2.2":
    msgutil.close_connection(request)
  elif request.ws_protocol == "test 6":
    resp = "wrong message"
    if msgutil.receive_message(request) == "1":
      resp = "2"
    msgutil.send_message(request, resp.decode('utf-8'))
    resp = "wrong message"
    if msgutil.receive_message(request) == "3":
      resp = "4"
    msgutil.send_message(request, resp.decode('utf-8'))
    resp = "wrong message"
    if msgutil.receive_message(request) == "5":
      resp = "あいうえお"
    msgutil.send_message(request, resp.decode('utf-8'))
  elif request.ws_protocol == "test 7":
    try:
      while not request.client_terminated:
        msgutil.receive_message(request)
    except msgutil.ConnectionTerminatedException, e:
      pass
    msgutil.send_message(request, "server data")
    msgutil.send_message(request, "server data")
    msgutil.send_message(request, "server data")
    msgutil.send_message(request, "server data")
    msgutil.send_message(request, "server data")
    time.sleep(30)
    msgutil.close_connection(request, True)
开发者ID:Kalamatee,项目名称:timberwolf,代码行数:29,代码来源:file_websocket_wsh.py

示例6: test_receive_message_deflate_stream

    def test_receive_message_deflate_stream(self):
        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        data = compress.compress('\x81\x85' + _mask_hybi('Hello'))
        data += compress.flush(zlib.Z_SYNC_FLUSH)
        data += compress.compress('\x81\x89' + _mask_hybi('WebSocket'))
        data += compress.flush(zlib.Z_FINISH)

        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)

        data += compress.compress('\x81\x85' + _mask_hybi('World'))
        data += compress.flush(zlib.Z_SYNC_FLUSH)
        # Close frame
        data += compress.compress(
            '\x88\x8a' + _mask_hybi(struct.pack('!H', 1000) + 'Good bye'))
        data += compress.flush(zlib.Z_SYNC_FLUSH)

        request = _create_request_from_rawdata(data, deflate_stream=True)
        self.assertEqual('Hello', msgutil.receive_message(request))
        self.assertEqual('WebSocket', msgutil.receive_message(request))
        self.assertEqual('World', msgutil.receive_message(request))

        self.assertFalse(request.drain_received_data_called)

        self.assertEqual(None, msgutil.receive_message(request))

        self.assertTrue(request.drain_received_data_called)
开发者ID:cscheid,项目名称:forte,代码行数:29,代码来源:test_msgutil.py

示例7: test_receive_message

    def test_receive_message(self):
        request = _create_request(("\x81\x85", "Hello"), ("\x81\x86", "World!"))
        self.assertEqual("Hello", msgutil.receive_message(request))
        self.assertEqual("World!", msgutil.receive_message(request))

        payload = "a" * 125
        request = _create_request(("\x81\xfd", payload))
        self.assertEqual(payload, msgutil.receive_message(request))
开发者ID:hinike,项目名称:opera,代码行数:8,代码来源:test_msgutil.py

示例8: test_receive_medium_message

    def test_receive_medium_message(self):
        payload = 'a' * 126
        request = _create_request(('\x81\xfe\x00\x7e', payload))
        self.assertEqual(payload, msgutil.receive_message(request))

        payload = 'a' * ((1 << 16) - 1)
        request = _create_request(('\x81\xfe\xff\xff', payload))
        self.assertEqual(payload, msgutil.receive_message(request))
开发者ID:cscheid,项目名称:forte,代码行数:8,代码来源:test_msgutil.py

示例9: test_receive_message_discard

 def test_receive_message_discard(self):
     request = _create_request(
         ("\x8f\x86", "IGNORE"), ("\x81\x85", "Hello"), ("\x8f\x89", "DISREGARD"), ("\x81\x86", "World!")
     )
     self.assertRaises(msgutil.UnsupportedFrameException, msgutil.receive_message, request)
     self.assertEqual("Hello", msgutil.receive_message(request))
     self.assertRaises(msgutil.UnsupportedFrameException, msgutil.receive_message, request)
     self.assertEqual("World!", msgutil.receive_message(request))
开发者ID:hinike,项目名称:opera,代码行数:8,代码来源:test_msgutil.py

示例10: test_receive_message

    def test_receive_message(self):
        request = _create_request(
            ('\x81\x85', 'Hello'), ('\x81\x86', 'World!'))
        self.assertEqual('Hello', msgutil.receive_message(request))
        self.assertEqual('World!', msgutil.receive_message(request))

        payload = 'a' * 125
        request = _create_request(('\x81\xfd', payload))
        self.assertEqual(payload, msgutil.receive_message(request))
开发者ID:cscheid,项目名称:forte,代码行数:9,代码来源:test_msgutil.py

示例11: test_receive_unsolicited_pong

    def test_receive_unsolicited_pong(self):
        # Unsolicited pong is allowed from HyBi 07.
        request = _create_request(("\x8a\x85", "Hello"), ("\x81\x85", "World"))
        msgutil.receive_message(request)

        request = _create_request(("\x8a\x85", "Hello"), ("\x81\x85", "World"))
        msgutil.send_ping(request, "Jumbo")
        # Body mismatch.
        msgutil.receive_message(request)
开发者ID:hinike,项目名称:opera,代码行数:9,代码来源:test_msgutil.py

示例12: test_receive_message_discard

 def test_receive_message_discard(self):
     request = _create_request(
         ('\x8f\x86', 'IGNORE'), ('\x81\x85', 'Hello'),
         ('\x8f\x89', 'DISREGARD'), ('\x81\x86', 'World!'))
     self.assertRaises(msgutil.UnsupportedFrameException,
                       msgutil.receive_message, request)
     self.assertEqual('Hello', msgutil.receive_message(request))
     self.assertRaises(msgutil.UnsupportedFrameException,
                       msgutil.receive_message, request)
     self.assertEqual('World!', msgutil.receive_message(request))
开发者ID:cscheid,项目名称:forte,代码行数:10,代码来源:test_msgutil.py

示例13: test_receive_unsolicited_pong

    def test_receive_unsolicited_pong(self):
        # Unsolicited pong is allowed from HyBi 07.
        request = _create_request(
            ('\x8a\x85', 'Hello'), ('\x81\x85', 'World'))
        msgutil.receive_message(request)

        request = _create_request(
            ('\x8a\x85', 'Hello'), ('\x81\x85', 'World'))
        msgutil.send_ping(request, 'Jumbo')
        # Body mismatch.
        msgutil.receive_message(request)
开发者ID:cscheid,项目名称:forte,代码行数:11,代码来源:test_msgutil.py

示例14: web_socket_transfer_data

def web_socket_transfer_data(request):
    global connections
    connections[request] = True
    socketName = None
    try:
        socketName = msgutil.receive_message(request)
        # notify to client that socketName is received by server.
        msgutil.send_message(request, socketName)
        msgutil.receive_message(request)  # wait, and exception by close.
        socketName = socketName + ': receive next message'
    finally:
        # request is closed. notify this socketName to other web sockets.
        del connections[request]
        for ws in connections.keys():
            msgutil.send_message(ws, socketName)
开发者ID:Andersbakken,项目名称:WebKit-mirror,代码行数:15,代码来源:close-on-unload_wsh.py

示例15: test_receive_fragments

 def test_receive_fragments(self):
     request = _create_request(
         ('\x01\x85', 'Hello'),
         ('\x00\x81', ' '),
         ('\x00\x85', 'World'),
         ('\x80\x81', '!'))
     self.assertEqual('Hello World!', msgutil.receive_message(request))
开发者ID:cscheid,项目名称:forte,代码行数:7,代码来源:test_msgutil.py


注:本文中的mod_pywebsocket.msgutil.receive_message函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。