Example #1
0
        def server(link):
            def on_recv(conn_id, data):
                container["received"].append(data)
            def on_disconnect(conn_id):
                link.stop()

            link.on_recv = on_recv
            link.on_disconnect = on_disconnect
            link.loop(runtime=LOOP_RUNTIME)
Example #2
0
        def server(link):
            def on_connect(conn_id):
                link.send(conn_id, b"a")

            def on_disconnect(conn_id):
                link.stop()

            link.on_connect = on_connect
            link.on_disconnect = on_disconnect
            link.loop(runtime=LOOP_RUNTIME)
Example #3
0
        def client(link, packeter):
            def on_connect(conn_id):
                packeter.send_packet(conn_id, to_send)

            def on_disconnect(conn_id):
                link.stop()

            packeter.on_connect = on_connect
            packeter.on_disconnect = on_disconnect
            link.loop(runtime=LOOP_RUNTIME)
Example #4
0
        def client(link, packeter):
            def on_connect(conn_id):
                packeter.send_packet(conn_id, to_send)

            def on_disconnect(conn_id):
                link.stop()

            packeter.on_connect = on_connect
            packeter.on_disconnect = on_disconnect
            link.loop(runtime=LOOP_RUNTIME)
Example #5
0
        def server(link):
            def on_connect(conn_id):
                link.send(conn_id, b"a")

            def on_disconnect(conn_id):
                link.stop()

            link.on_connect = on_connect
            link.on_disconnect = on_disconnect
            link.loop(runtime=LOOP_RUNTIME)
Example #6
0
        def server(link):
            def on_recv(conn_id, data):
                container["received"].append(data)

            def on_disconnect(conn_id):
                link.stop()

            link.on_recv = on_recv
            link.on_disconnect = on_disconnect
            link.loop(runtime=LOOP_RUNTIME)
Example #7
0
        def client(link):
            def on_connect(conn_id):
                link.send(conn_id, data_to_send)
            def on_ready_to_send(conn_id, last_send_size):
                container["sent"] = data_to_send[:last_send_size]
                link.close(conn_id)
                link.stop()

            link.on_connect = on_connect
            link.on_ready_to_send = on_ready_to_send
            link.loop(runtime=LOOP_RUNTIME)
Example #8
0
        def server(link, packeter):
            def on_recv(conn_id, packet):
                container["received"] = packet
                link.close(conn_id)

            def on_disconnect(conn_id):
                link.stop()

            packeter.on_packet_recv = on_recv
            packeter.on_disconnect = on_disconnect
            link.loop(runtime=LOOP_RUNTIME)
Example #9
0
        def server(link, packeter):
            def on_recv(conn_id, packet):
                container["received"] = packet
                link.close(conn_id)

            def on_disconnect(conn_id):
                link.stop()

            packeter.on_packet_recv = on_recv
            packeter.on_disconnect = on_disconnect
            link.loop(runtime=LOOP_RUNTIME)
Example #10
0
        def client(link):
            def on_connect(conn_id):
                link.send(conn_id, data_to_send)

            def on_ready_to_send(conn_id, last_send_size):
                container["sent"] = data_to_send[:last_send_size]
                link.close(conn_id)
                link.stop()

            link.on_connect = on_connect
            link.on_ready_to_send = on_ready_to_send
            link.loop(runtime=LOOP_RUNTIME)
Example #11
0
        def client(link, packeter):
            def on_connect(conn_id):
                for data in to_send:
                    packeter.send_packet(conn_id, data)

            def on_disconnect(conn_id):
                link.stop()

            packeter.on_connect = on_connect
            packeter.on_disconnect = on_disconnect
            try:
                link.loop(runtime=LOOP_RUNTIME)
            except Exception as e:
                import traceback
                traceback.print_exc()
Example #12
0
        def client(link, packeter):
            def on_connect(conn_id):
                for data in to_send:
                    packeter.send_packet(conn_id, data)

            def on_disconnect(conn_id):
                link.stop()

            packeter.on_connect = on_connect
            packeter.on_disconnect = on_disconnect
            try:
                link.loop(runtime=LOOP_RUNTIME)
            except Exception as e:
                import traceback
                traceback.print_exc()
Example #13
0
        def client(link):
            def on_recv(conn_id, packet):
                link.close(conn_id) # <- close in recv

            def on_disconnect(conn_id):
                link.stop()

            link.on_recv = on_recv
            link.on_disconnect = on_disconnect

            # handle_close must be called only 1x
            link_wrapper = mock.Mock(wraps=link)
            with mock.patch.object(link, "handle_close",
                                    link_wrapper.handle_close):
                link.loop(runtime=LOOP_RUNTIME)
            self.assertEqual(link_wrapper.handle_close.call_count, 1)
Example #14
0
        def client(link):
            def on_recv(conn_id, packet):
                link.close(conn_id)  # <- close in recv

            def on_disconnect(conn_id):
                link.stop()

            link.on_recv = on_recv
            link.on_disconnect = on_disconnect

            # handle_close must be called only 1x
            link_wrapper = mock.Mock(wraps=link)
            with mock.patch.object(link, "handle_close",
                                   link_wrapper.handle_close):
                link.loop(runtime=LOOP_RUNTIME)
            self.assertEqual(link_wrapper.handle_close.call_count, 1)
Example #15
0
File: mm.py Project: caimaoy/uhp
def send(msg, ttl=None):
    if config.fade_windows:
        return True;
    link = snakemq.link.Link()
    link.add_connector((config.mq_host, config.mq_port))
    packeter = snakemq.packeter.Packeter(link)
    messaging = snakemq.messaging.Messaging('uhpweb', "", packeter)

    msg_num = [1]
    def _inner_on_message_sent(conn_id, ident, message_uuid):
        link.stop()
        msg_num[0] = 0

    messaging.on_message_sent.add(_inner_on_message_sent)
    
    message = snakemq.message.Message(msg, ttl=ttl)
    messaging.send_message("worker", message)

    link.loop(runtime=3)
    link.cleanup()
   
    return msg_num[0] == 0 
Example #16
0
def send(msg, ttl=None):
    #delete the fade windows conf
    #if config.fade_windows:
    #    return True;
    link = snakemq.link.Link()
    link.add_connector((config.mq_host, config.mq_port))
    packeter = snakemq.packeter.Packeter(link)
    messaging = snakemq.messaging.Messaging('uhpweb', "", packeter)

    msg_num = [1]
    def _inner_on_message_sent(conn_id, ident, message_uuid):
        link.stop()
        msg_num[0] = 0

    messaging.on_message_sent.add(_inner_on_message_sent)
    
    message = snakemq.message.Message(msg, ttl=ttl)
    messaging.send_message("worker", message)

    link.loop(runtime=3)
    link.cleanup()
   
    return msg_num[0] == 0