Socket Server Tools
Use sockets easily
Installation
To install the latest version run Unix/macOS:
python3 -m pip install sockettools
Windows:
py -m pip install sockettools
To install a specified release run Unix/maxOS
python3 -m pip install sockettools=[version]
Windows:
py -m pip install sockettools=[version]
Quickstart
server.py:
import network
class TransferProtocol(network.Protocol):
@classmethod
def encode(cls, data):
# This function gets data that the program wants to send and encodes it to bytearray or bytes to send to socket
return data
@classmethod
def decode(cls, data : bytearray):
# This function is called every tome some data is recieved
# returns CONTINUE if data should be continued to be recieved and data param is continued to be built up
# If the function returns data: data param is reset and resu't is returned
return data
class ClientHandler(network.ClientHandler):
protocol = TransferProtocol # This protocol only allows sending and recieving binary data
def __init__(self, conn, addr, server):
# This function is called it the main thread when a client connects
# conn - socket object of the client connection
# addr - client address
# server - Server which created the client hander
# You sould call the original init for the handler to work
super().__init__(conn, addr, server)
def serve():
# This function is called in a separate thread after the init
self.transport.run_background() # Activates events
self.event.register(self.event.PACKET_RECIEVED, self.on_recieved)
def on_recieved(self, data):
self.transport.send(data)
echo_server = network.Server(host="0.0.0.0", port=8085, handler=ClientHandler)
echo_server.run()
client.py:
import network
class TransferProtocol(same as in server.py)
class Client(network.Client):
protocol = TransferProtocol
# Same as ClientHandler
def serve():
...
self.transport.send(b"Echo test")
def on_recieved(self, data):
print(data)
client = Client.conect("127.0.0.1", 8085)
client.run()
Metadata
Release files for sockettools 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 | |
|---|---|---|---|
| sockettools-1.0.1.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sockettools-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.8 kB
Release files / sockettools-1.0.1.tar.gz
| Download URL | sockettools-1.0.1.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d04e19685a71646ab54335eb23d415955ef0e4f9da10dee65aeafe66ce27bd5
|
|
BLAKE2b-256 checksum How to use checksums |
bcb0f6a0152024ee4cc6dc2e70f95a314e4a568962a38f24fdc0f571474ef5a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.3
|
Release files / sockettools-1.0.1-py3-none-any.whl
| Download URL | sockettools-1.0.1-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f88c33d3b12d1ca4d16b228418fff2d85a8338146626d017dec103eab9576e53
|
|
BLAKE2b-256 checksum How to use checksums |
45d25132c2a3e5245836d8f792c42e71967a441b7c35da7b8a451aa3df9d1d8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.3
|