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

Python msgutil.send_message函数代码示例

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

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



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

示例1: web_socket_transfer_data

def web_socket_transfer_data(request):
    pragma = request.headers_in.get('Pragma')
    cache_control = request.headers_in.get('Cache-Control')
    if pragma == 'no-cache' and cache_control == 'no-cache':
        msgutil.send_message(request, 'PASS')
    else:
        msgutil.send_message(request, 'FAIL')
开发者ID:335969568,项目名称:Blink-1,代码行数:7,代码来源:nocache-test_wsh.py


示例2: 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


示例3: test_send_message_permessage_compress_deflate_fragmented_bfinal

    def test_send_message_permessage_compress_deflate_fragmented_bfinal(self):
        extension = common.ExtensionParameter(
            common.PERMESSAGE_COMPRESSION_EXTENSION)
        extension.add_parameter('method', 'deflate')
        request = _create_request_from_rawdata(
                      '', permessage_compression_request=extension)
        self.assertEquals(1, len(request.ws_extension_processors))
        compression_processor = (
            request.ws_extension_processors[0].get_compression_processor())
        compression_processor.set_bfinal(True)
        msgutil.send_message(request, 'Hello', end=False)
        msgutil.send_message(request, 'World', end=True)

        expected = ''

        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)
        compressed_hello = compress.compress('Hello')
        compressed_hello += compress.flush(zlib.Z_FINISH)
        compressed_hello = compressed_hello + chr(0)
        expected += '\x41%c' % len(compressed_hello)
        expected += compressed_hello

        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)
        compressed_world = compress.compress('World')
        compressed_world += compress.flush(zlib.Z_FINISH)
        compressed_world = compressed_world + chr(0)
        expected += '\x80%c' % len(compressed_world)
        expected += compressed_world

        self.assertEqual(expected, request.connection.written_data())
开发者ID:XiaonuoGantan,项目名称:pywebsocket,代码行数:32,代码来源:test_msgutil.py


示例4: test_send_message_deflate_frame_bfinal

    def test_send_message_deflate_frame_bfinal(self):
        extension = common.ExtensionParameter(common.DEFLATE_FRAME_EXTENSION)
        request = _create_request_from_rawdata(
            '', deflate_frame_request=extension)
        self.assertEquals(1, len(request.ws_extension_processors))
        deflate_frame_processor = request.ws_extension_processors[0]
        deflate_frame_processor.set_bfinal(True)
        msgutil.send_message(request, 'Hello')
        msgutil.send_message(request, 'World')

        expected = ''

        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)
        compressed_hello = compress.compress('Hello')
        compressed_hello += compress.flush(zlib.Z_FINISH)
        compressed_hello = compressed_hello + chr(0)
        expected += '\xc1%c' % len(compressed_hello)
        expected += compressed_hello

        compress = zlib.compressobj(
            zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)
        compressed_world = compress.compress('World')
        compressed_world += compress.flush(zlib.Z_FINISH)
        compressed_world = compressed_world + chr(0)
        expected += '\xc1%c' % len(compressed_world)
        expected += compressed_world

        self.assertEqual(expected, request.connection.written_data())
开发者ID:XiaonuoGantan,项目名称:pywebsocket,代码行数:29,代码来源:test_msgutil.py


示例5: onPublish

 def onPublish(self, mosq, obj, mid):
     if _status_ == _OPEN_:
         try:
             string = json.dumps({"topic": self.topic + "/server", "message": "Message published to broker"})
             msgutil.send_message(self.socket, string)
         except Exception:
             return
开发者ID:justinribeiro,项目名称:ReplicatorG-websocketserver,代码行数:7,代码来源:broker_wsh.py


示例6: onMessage

 def onMessage(self, mosq, obj, msg):
     if _status_ == _OPEN_:
         try:
             string = json.dumps({"topic": msg.topic, "message": msg.payload})
             msgutil.send_message(self.socket, string)
         except Exception:
             return
开发者ID:justinribeiro,项目名称:ReplicatorG-websocketserver,代码行数:7,代码来源:broker_wsh.py


示例7: web_socket_transfer_data

def web_socket_transfer_data(request):
    for i in range(1, 128):
        request.connection.write(chr(i) + str(i) + '\xff')
    for i in range(128, 256):
        msg = str(i)
        request.connection.write(chr(i) + chr(len(msg)) + msg)
    msgutil.send_message(request, 'done')
开发者ID:azrul2202,项目名称:WebKit-Smartphone,代码行数:7,代码来源:unknown-frame-type_wsh.py


示例8: 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


示例9: test_send_message_deflate_frame

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

        extension = common.ExtensionParameter(common.DEFLATE_FRAME_EXTENSION)
        request = _create_request_from_rawdata(
            '', deflate_frame_request=extension)
        msgutil.send_message(request, 'Hello')
        msgutil.send_message(request, 'World')

        expected = ''

        compressed_hello = compress.compress('Hello')
        compressed_hello += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_hello = compressed_hello[:-4]
        expected += '\xc1%c' % len(compressed_hello)
        expected += compressed_hello

        compressed_world = compress.compress('World')
        compressed_world += compress.flush(zlib.Z_SYNC_FLUSH)
        compressed_world = compressed_world[:-4]
        expected += '\xc1%c' % len(compressed_world)
        expected += compressed_world

        self.assertEqual(expected, request.connection.written_data())
开发者ID:cscheid,项目名称:forte,代码行数:25,代码来源:test_msgutil.py


示例10: web_socket_transfer_data

def web_socket_transfer_data(request):
    while True:
        line = request.ws_stream.receive_message()
        if line == "echo":
            query = request.unparsed_uri.split('?')[1]
            GET = dict(urllib.parse.parse_qsl(query))

            # TODO(kristijanburnik): This code should be reused from
            # /mixed-content/generic/expect.py or implemented more generally
            # for other tests.
            path = GET.get("path", request.unparsed_uri.split('?')[0])
            key = GET["key"]
            action = GET["action"]

            if action == "put":
              value = GET["value"]
              stash.take(key=key, path=path)
              stash.put(key=key, value=value, path=path)
              response_data = json.dumps({"status": "success", "result": key})
            elif action == "purge":
             value = stash.take(key=key, path=path)
             response_data = json.dumps({"status": "success", "result": value})
            elif action == "take":
              value = stash.take(key=key, path=path)
              if value is None:
                  status = "allowed"
              else:
                  status = "blocked"
              response_data = json.dumps({"status": status, "result": value})

            msgutil.send_message(request, response_data)

            return
开发者ID:Coder206,项目名称:servo,代码行数:33,代码来源:stash_responder_wsh.py


示例11: web_socket_transfer_data

def web_socket_transfer_data(request):
    lastmsg = ''
    r = redis.Redis()
    timelim = time.time() + timeout
    
    while True:
        #words = msgutil.receive_message(request)
        #if words == __KillerWords__:
        #    break
            
        # get last 10 messages
        messages = r.lrange('msgs',0,9)
        try:
            # give remaining messages from buffer
            lastindex = messages.index(lastmsg)
            if (lastindex>0):
                timelim = time.time() + timeout
                for i in xrange(0,lastindex):
                    msgutil.send_message(request,
                                    messages[lastindex - i -1].split('|',1)[1])
        except ValueError:
            # client has not received anything at all, give the whole buffer
            for msg in messages[::-1]:
                msgutil.send_message(request, msg.split('|',1)[1])
            timelim = time.time() + timeout
            
        lastmsg = messages[0]

        if (time.time() > timelim):
            print "A receive timedout"
            r.disconnect()
            break
开发者ID:ideamonk,项目名称:BakaBot,代码行数:32,代码来源:receive_wsh.py


示例12: web_socket_transfer_data

def web_socket_transfer_data(request):
    # pywebsocket does not mask message by default. We need to build a frame manually to mask it.
    request.connection.write(stream.create_text_frame('First message', mask=False))

    request.connection.write(stream.create_text_frame('Fragmented ', opcode=common.OPCODE_TEXT, fin=0, mask=False))
    request.connection.write(stream.create_text_frame('message', opcode=common.OPCODE_CONTINUATION, fin=1, mask=False))

    request.connection.write(stream.create_text_frame('', mask=False))

    msgutil.send_message(request, 'END')

    # Wait for the client to start closing handshake.
    # To receive a close frame, we must use an internal method of request.ws_stream.
    opcode, payload, final, reserved1, reserved2, reserved3 = request.ws_stream._receive_frame()
    assert opcode == common.OPCODE_CLOSE
    assert final
    assert not reserved1
    assert not reserved2
    assert not reserved3

    # Send a masked close frame. Clients should be able to handle this frame and
    # the WebSocket object should be closed cleanly.
    request.connection.write(stream.create_close_frame('', mask=False))

    # Prevents pywebsocket from starting its own closing handshake.
    raise handshake.AbortedByUserException('Abort the connection')
开发者ID:335969568,项目名称:Blink-1,代码行数:26,代码来源:unmasked-frames_wsh.py


示例13: web_socket_transfer_data

def web_socket_transfer_data(request):
	while True:
		s = msgutil.receive_message(request)
		for connect in arr:
			try:
				msgutil.send_message(connect, s)
			except:
				arr.remove(connect)
开发者ID:yanaitamon,项目名称:cpp_py,代码行数:8,代码来源:chat_wsh.py


示例14: test_send_message_deflate_stream

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

        request = _create_request_from_rawdata("", deflate_stream=True)
        msgutil.send_message(request, "Hello")
        expected = compress.compress("\x81\x05Hello")
        expected += compress.flush(zlib.Z_SYNC_FLUSH)
        self.assertEqual(expected, request.connection.written_data())
开发者ID:hinike,项目名称:opera,代码行数:8,代码来源:test_msgutil.py


示例15: web_socket_transfer_data

def web_socket_transfer_data(request):
    while True:
        line = msgutil.receive_message(request)
        print "received:", line
        line = str(int(line)*2)
        msgutil.send_message(request, line)
        if line == _GOODBYE_MESSAGE:
            return
开发者ID:danx0r,项目名称:websocket,代码行数:8,代码来源:wstest_wsh.py


示例16: web_socket_transfer_data

def web_socket_transfer_data(request):
  while True:
    rcvd = msgutil.receive_message(request)
    opcode = request.ws_stream.get_last_received_opcode()
    if (opcode == common.OPCODE_BINARY):
      msgutil.send_message(request, rcvd, binary=True)
    elif (opcode == common.OPCODE_TEXT):
      msgutil.send_message(request, rcvd)
开发者ID:70599,项目名称:Waterfox,代码行数:8,代码来源:file_websocket_permessage_deflate_params_wsh.py


示例17: listen_psirp_updates

def listen_psirp_updates(request, subscriber):
  while True:
    for version in subscriber.listen():
      if version is not None: # if publication exists
        print('Sending from Blackhawk: %s' % str(version.buffer))
        msgutil.send_message(request, '%s' % str(version.buffer))
      else:
        print("Received Publishment was null :(")
开发者ID:mainul,项目名称:psirp-cc2010,代码行数:8,代码来源:duplex_subscriber_wsh.py


示例18: web_socket_transfer_data

def web_socket_transfer_data(request):
    match = re.search(r"\?opcode=(\d+)$", request.ws_resource)
    if match is None:
        msgutil.send_message(request, "FAIL: Query value is incorrect or missing")
        return

    opcode = int(match.group(1))
    payload = "This text should be ignored. (opcode = %d)" % opcode
    request.connection.write(stream.create_header(opcode, len(payload), 1, 0, 0, 0, 0) + payload)
开发者ID:RoninHsu,项目名称:webkit,代码行数:9,代码来源:reserved-opcodes_wsh.py


示例19: initialize_subscriber

def initialize_subscriber(request):
  line = msgutil.receive_message(request).encode('utf-8')
  try:
    msg = json.loads(line)
    sid = str(msg["subscribe"]["sid"])
    rid = str(msg["subscribe"]["rid"])
  except ValueError, e:
    msgutil.send_message(request, '%s' % json_message("message", str(e) + " " + line))
    return False
开发者ID:mainul,项目名称:psirp-cc2010,代码行数:9,代码来源:duplex_subscriber_wsh.py


示例20: test_send_message

    def test_send_message(self):
        request = _create_request()
        msgutil.send_message(request, "Hello")
        self.assertEqual("\x81\x05Hello", request.connection.written_data())

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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python util.get_class_logger函数代码示例发布时间:2022-05-27
下一篇:
Python msgutil.receive_message函数代码示例发布时间: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