• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python msgutil.receive_message函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: web_socket_transfer_data

def web_socket_transfer_data(request):
	global _status_
	_status_ = _OPEN_
	arr = ()
	thread.start_new_thread(tail(file, 0.5, request).run, arr)
	while True:
		try:
			#######################################################
			# Note::
			# mesgutil.receive_message() returns 'unicode', so
			# if you want to treated as 'string', use encode('utf-8')
			#######################################################
			line = msgutil.receive_message(request).encode('utf-8')
			
			if line == _HEARTBEAT_:
				continue
		
			f = open(file, 'a')
			f.write(line+"\n")
			os.fsync(f.fileno())
			f.flush()
			f.close
			
		except Exception:
			_status_ = _CLOSING_
			# wait until _status_ change.
			i = 0
			while _status_ == _CLOSING_:
				time.sleep(0.5)
				i += 1
				if i > 10:
					break
			return
开发者ID:minwook1,项目名称:websocket-sample,代码行数:33,代码来源:do_wsh.py


示例17: test_receive_fragments_unicode

 def test_receive_fragments_unicode(self):
     # UTF-8 encodes U+6f22 into e6bca2 and U+5b57 into e5ad97.
     request = _create_request(
         ('\x01\x82', '\xe6\xbc'),
         ('\x00\x82', '\xa2\xe5'),
         ('\x80\x82', '\xad\x97'))
     self.assertEqual(u'\u6f22\u5b57', msgutil.receive_message(request))
开发者ID:cscheid,项目名称:forte,代码行数:7,代码来源:test_msgutil.py


示例18: test_receive_ping

    def test_receive_ping(self):
        """Tests receiving a ping control frame."""

        def handler(request, message):
            request.called = True

        # Stream automatically respond to ping with pong without any action
        # by application layer.
        request = _create_request(("\x89\x85", "Hello"), ("\x81\x85", "World"))
        self.assertEqual("World", msgutil.receive_message(request))
        self.assertEqual("\x8a\x05Hello", request.connection.written_data())

        request = _create_request(("\x89\x85", "Hello"), ("\x81\x85", "World"))
        request.on_ping_handler = handler
        self.assertEqual("World", msgutil.receive_message(request))
        self.assertTrue(request.called)
开发者ID:hinike,项目名称:opera,代码行数:16,代码来源:test_msgutil.py


示例19: web_socket_transfer_data

def web_socket_transfer_data(request):
    from urlparse import urlparse
    from urlparse import parse_qs
    #requests.append(request)
    url = urlparse(request.get_uri())
    query = parse_qs(url.query)
    if query.has_key('projectName'):
        projectNames = query["projectName"]
        if len(projectNames) == 1:
            projectName = projectNames[0]
            if not rooms.has_key(projectName):
                rooms[projectName] = []
            rooms[projectName].append(request)
    while True:
        try:
            message = msgutil.receive_message(request)
        except Exception:
            return
        #for req in requests:
        #    try:
        #        msgutil.send_message(req, message)
        #    except Exception:
        #        requests.remove(req)
        for req in rooms[projectName]:
            try:
                msgutil.send_message(req, message)
            except Exception:
                rooms[projectName].remove(req)
                if len(rooms[projectName]) == 0:
                    del rooms[projectName]
开发者ID:Kanasansoft,项目名称:TraChat,代码行数:30,代码来源:trachat_wsh.py


示例20: web_socket_transfer_data

def web_socket_transfer_data(request):
    # request.connection.remote_ip
    UDPSock = socket(AF_INET,SOCK_DGRAM)
    r = redis.Redis()
    timelim = time.time() + timeout
    while True:
        data = msgutil.receive_message(request)
        if time.time() > timelim:
            print "A send timed out"
            UDPSock.close()
            r.disconnect()
            break
            
        if data == __KillerWords__:
            print "A send did suicide"
            UDPSock.close()
            r.disconnect()
            break
            
        timelim = time.time() + timeout
        data = data.replace ('<','&lt;').replace('>','&gt;')[:max_msg_size]
        message = '%s|user%s' % (time.time(), data)
        r.push ('msgs',message,head=True)
        if (message.find('@baka ') > 0):
            # send a copy to bokkabot
            UDPSock.sendto(message,addr)
开发者ID:ideamonk,项目名称:BakaBot,代码行数:26,代码来源:send_wsh.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python msgutil.send_message函数代码示例发布时间:2022-05-27
下一篇:
Python common.is_control_opcode函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap