def test_no_reconnect(self):
        connection = HubConnectionBuilder()\
            .with_url(self.server_url, options={"verify_ssl": False})\
            .configure_logging(logging.ERROR)\
            .build()

        _lock = threading.Lock()

        _lock.acquire(timeout=10)

        connection.on_open(lambda: _lock.release())

        connection.on("ReceiveMessage", lambda _: _lock.release())

        connection.start()

        self.assertTrue(_lock.acquire(timeout=10))  # Released on ReOpen

        connection.send("DisconnectMe", [])

        self.assertTrue(_lock.acquire(timeout=10))

        time.sleep(10)

        self.assertRaises(HubConnectionError,
                          lambda: connection.send("DisconnectMe", []))

        connection.stop()
        del _lock
Exemplo n.º 2
0
time.sleep(10)


def bye(error, x):
    if error:
        print("error {0}".format(x))
    else:
        print("complete! ")
    global hub_connection
    hub_connection.stop()
    sys.exit(0)


iteration = 0
subject = Subject()


def interval_handle():
    global iteration
    iteration += 1
    subject.next(str(iteration))
    if iteration == 10:
        subject.complete()


hub_connection.send("UploadStream", subject)

while iteration != 10:
    interval_handle()
    time.sleep(0.5)
    .with_url(server_url)\
    .configure_logging(logging.DEBUG)\
    .build()

hub_connection.on_open(lambda: print(
    "connection opened and handshake received ready to send messages"))
hub_connection.on_close(lambda: reconnect)


def reconnect():
    print("connection closed")
    time.sleep(20)
    print("try reconnect")
    hub_connection.start()


hub_connection.on("ReceiveMessage", print)
hub_connection.start()
message = None

# Do login

while message != "exit()":
    message = input(">> ")
    if message is not None and message != "" and message != "exit()":
        hub_connection.send("SendMessage", [username, message])

hub_connection.stop()

sys.exit(0)
Exemplo n.º 4
0
hub_connection = HubConnectionBuilder()\
    .with_url(server_url, options={"verify_ssl": False}) \
    .configure_logging(logging.ERROR, socket_trace=False, handler=handler) \
    .with_automatic_reconnect({
            "type": "interval",
            "keep_alive_interval": 10,
            "intervals": [1, 3, 5, 6, 7, 87, 3]
        })\
    .with_hub_protocol(MessagePackHubProtocol())\
    .build()

hub_connection.on_open(lambda: print(
    "connection opened and handshake received ready to send messages"))
hub_connection.on_close(lambda: print("connection closed"))

hub_connection.on("ReceiveMessage", print)
hub_connection.start()
message = None

# Do login

while message != "exit()":
    message = input(">> ")
    if message is not None and message != "" and message != "exit()":
        hub_connection.send("SendMessage", [username, message],
                            lambda args: print(args, "<-------------------"))

hub_connection.stop()

sys.exit(0)
Exemplo n.º 5
0
login_url = input_with_default('Enter your server login url({0}):',
                               "http://*****:*****@mandrewcito.com")
password = input_with_default('Enter your password (default: {0}): ',
                              "Abc123.--123?")

hub_connection = HubConnectionBuilder()\
    .with_url(server_url, options={
        "access_token_factory": lambda: signalr_core_example_login(login_url, username, password)
    }).with_automatic_reconnect({
        "type": "interval",
        "keep_alive_interval": 10,
        "intervals": [1, 3, 5, 6, 7, 87, 3]
    })\
    .build()

hub_connection.on("ReceiveSystemMessage", print_message)
hub_connection.on("ReceiveChatMessage", print_message)
hub_connection.on("ReceiveDirectMessage", print_message)
hub_connection.start()
message = None
while message != "exit()":
    message = raw_input(">> ")
    if message is not None and message is not "" and message is not "exit()":
        hub_connection.send("Send", [message])
hub_connection.stop()
Exemplo n.º 6
0
handler.setLevel(logging.DEBUG)
hub_connection = HubConnectionBuilder()\
    .with_url(server_url, options={"verify_ssl": False}) \
    .configure_logging(logging.DEBUG, socket_trace=True, handler=handler) \
    .with_automatic_reconnect({
            "type": "interval",
            "keep_alive_interval": 10,
            "intervals": [1, 3, 5, 6, 7, 87, 3]
        }).build()

hub_connection.on_open(lambda: print(
    "connection opened and handshake received ready to send messages"))
hub_connection.on_close(lambda: print(
    "connection closed>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<"))
hub_connection.on_error(lambda err: print("errrrrrrrrrrrrrrrrrrr"))

hub_connection.on("ThrowExceptionCall", lambda x: print(f">>>{x}"))
hub_connection.start()
message = None

# Do login

while message != "exit()":
    message = input(">> ")
    if message is not None and message != "" and message != "exit()":
        hub_connection.send("ThrowException", [message])

hub_connection.stop()

sys.exit(0)
Exemplo n.º 7
0
sys.path.append("./")

from aiosignalrcore.hub_connection_builder import HubConnectionBuilder

connection = HubConnectionBuilder()\
    .with_url("wss://localhost:5001/chathub", options={"verify_ssl": False})\
    .configure_logging(logging.ERROR)\
    .build()

_lock = threading.Lock()

connection.on_open(lambda: _lock.release())
connection.on_close(lambda: _lock.release())

connection.on("ReceiveMessage", lambda _: _lock.release())

(_lock.acquire(timeout=30))  # Released on open

connection.start()

(_lock.acquire(timeout=30))  # Released on ReOpen

connection.send("DisconnectMe", [])

time.sleep(30)

(_lock.acquire(timeout=30))

connection.send("DisconnectMe", [])