A Python SignalR Core client
Project description
SignalR core client
Example
Using package from aspnet core - SignalRChat example chat without auth
from signalrcore.hub_connection import HubConnection
def input_with_default(input_text, default_value):
value = input(input_text.format(default_value))
return default_value if value is None or value.strip() == "" else value
server_url = input_with_default('Enter your server url(default: {0}): ', "ws://localhost:62342/chathub")
username = input_with_default('Enter your username (default: {0}): ', "mandrewcito")
# password = input_with_default('Enter your password (default: {0}): ', "Abc123.--123?")
hub_connection = HubConnection(server_url)
hub_connection.build()
hub_connection.on("ReceiveMessage", print)
hub_connection.start()
message = None
# Do login
while message != "exit()":
message = input(">> ")
if message is not None and message is not "" and message is not "exit()":
hub_connection.send("SendMessage", [username, message])
hub_connection.stop()
Using package from aspnet core - SignalRAuthenticationSample ,
Example with Auth
import requests
from signalrcore.hub_connection import HubConnection
def input_with_default(input_text, default_value):
value = input(input_text.format(default_value))
return default_value if value is None or value.strip() == "" else value
def signalr_core_example_login(url, user, username_password):
response = requests.post(url, data={"email": user, "password": username_password})
return response.json()["token"]
login_url = input_with_default('Enter your server login url({0}):', "http://localhost:50746/account/token")
server_url = input_with_default('Enter your server url(default: {0}): ', "ws://localhost:50746/hubs/chat")
username = input_with_default('Enter your username (default: {0}): ', "mandrewcito@mandrewcito.com")
password = input_with_default('Enter your password (default: {0}): ', "Abc123.--123?")
# Login
token = signalr_core_example_login(login_url, username, password)
hub_connection = HubConnection(
server_url,
token=token,
negotiate_headers={"Authorization": "Bearer " + token})
hub_connection.build()
hub_connection.on("ReceiveSystemMessage", print)
hub_connection.on("ReceiveChatMessage", print)
hub_connection.on("ReceiveDirectMessage", print)
hub_connection.start()
message = None
while message != "exit()":
message = input(">> ")
if message is not None and message is not "" and message is not "exit()":
hub_connection.send("Send", [message])
hub_connection.stop()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
signalrcore-0.3.0.tar.gz
(8.1 kB
view details)
Built Distribution
File details
Details for the file signalrcore-0.3.0.tar.gz
.
File metadata
- Download URL: signalrcore-0.3.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be20610ab51607e11ecbc56258969b1e67dda906f7d6262bcbec0c14d7782df6 |
|
MD5 | 5e61ac314454106d8d2614fa5a6a3f63 |
|
BLAKE2b-256 | faef9bdda2a998f23a067a8938b50b90410b1846b46afa8a2b23e724e4db6159 |
File details
Details for the file signalrcore-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: signalrcore-0.3.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 807d977e556b14264a9da535d838e0f437aa3cf52bd10adacc08194e52aa7b3c |
|
MD5 | 9604c922cfa86c93c9e277b4ad598730 |
|
BLAKE2b-256 | b0629d977449d3d84359c47374093bbec2d5f6dffef53d9aa984188a20508449 |