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


Python msgutil.send_message函数代码示例

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


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


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