Sockdot
simplified tcp networking library
note: This is not a websocket.
sockdot allows you to create server/client applications without having to use web-standard protocols in your application. the library is a threaded tcp socket and allows for events to be used, making it easy to inpliment in server/client application. i created this library to meet my needs in a Lan software project, so 't could be of use to someone else :).
Installation
pip install sockdot
Installing from source.
git clone https://github.com/rubbiekelvin/sockdot.git
cd sockdot
python setup.py sdist bdist_wheel
pip install dist\sockdot-1.0.1-py3-none-any.whl
Usage
server.py
from sockdot import Server
from sockdot.events import Event
serverevents = Event()
server = Server(debug=True)
@serverevents.event
def on_data_recieved(client, data):
print("recieved:", data)
server.send(client, f"you said {data}")
@serverevents.event
def on_connection_open(client):
print(f"client {client} joined")
@serverevents.event
def on_connection_close(client):
print(client, "closed connection")
@serverevents.event
def on_server_destruct():
print("server shutdown")
@serverevents.event
def on_error(exception, message):
# print(f"error {exception} occured, message:", message)
pass
@serverevents.event
def on_port_changed(port):
print("server changed port to", port)
@serverevents.event
def on_running_changed(running):
print("server is running" if running else "server is not running")
server.updateevent(serverevents)
server.run()
the server's runs on the machine's host name
from sockdot import host
print(host())
# outputs ["host_name", "host_ip"]
client.py
import time, threading
from sockdot import Client
from sockdot.events import Event
clientevents = Event()
client = Client(host="rubbie-io", debug=True)
def start(connected):
if connected:
for i in range(10):
client.send(str(i))
time.sleep(4)
client.close()
@clientevents.event
def on_data_recieved(data):
print(f"got {data} from server")
@clientevents.event
def on_connected_changed(connected):
threading.Thread(target=start, args=(connected,)).start()
@clientevents.event
def on_error(exception, message):
print(f"error {exception} occured, message:", message)
@clientevents.event
def on_host_changed(host):
pass
@clientevents.event
def on_port_changed(port):
pass
@clientevents.event
def on_handshake_started():
pass
@clientevents.event
def on_handshake_ended(result):
pass
client.updateevent(clientevents)
client.connect()
Adding authenthecation
create a file ".auth", could be anything you want, but in my case, i named it ".auth". the file contains keys and values of security parameters in json format.
{
"SECURITY_KEY" : "secret key",
"WHITELIST": [],
"BLACKLIST": [],
"USE_WHITELIST": false
}
in server.py, make this change:
note that it is also possible for auth settings to be in a python dictionary, use could use any one you want. the auth keyword argument can be a str (filename) type or dict (auth dictionary).
# from file...
server = Server(debug=True, auth=".auth")
# from dictionary
server = Server(debug=True, auth={
"SECURITY_KEY" : "secret key",
"WHITELIST": [],
"BLACKLIST": [],
"USE_WHITELIST": False
})
in client.py, make this change:
client.connect(authkey="secret key")
Metadata
Release files for sockdot 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sockdot-1.0.1.tar.gz | 5.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sockdot-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.8 kB
Release files / sockdot-1.0.1.tar.gz
| Download URL | sockdot-1.0.1.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2a70796c7c4134c09370e6ce27674f5a077b66f06fec583b4dc279b8686ae56b
|
|
BLAKE2b-256 checksum How to use checksums |
8f3b76719ddab16e319cfe325283a96c457eaefea8110872dac3fa082a3ba942
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0
|
Release files / sockdot-1.0.1-py3-none-any.whl
| Download URL | sockdot-1.0.1-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7a6e356d32f5202e44ff235b8d518c64ea56cd12061e08c19246d80d13fce2c
|
|
BLAKE2b-256 checksum How to use checksums |
db1d2f8a078635b2344d8f940ddeb2aa7339b40ddc3c54d9cbb13e31fee1aa86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0
|
Security for sockdot 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.