A simple module to encapsulate the built-in socket with struct.pack.
Project description
Structured Socket
A simple module to encapsulate the built-in socket with struct.pack so that the amount of data received can be forseen by the receiver to prevent sticking packets.
Repository: https://github.com/origamizyt/StructuredSocket (I believe that you can understand the mechanisms without the source code.)
Installation
This module is available on PyPI.
pip install structsock
Or you can install from source .tar.gz either.
python setup.py install
Usage
The exposed interfaces in this module is pretty the same as the built-in module socket, only replacing socket.socket with StructuredSocket:
# server side
from structsock import StructuredSocket
s = StructuredSocket()
s.bind(('0.0.0.0', 5000))
s.listen(5)
c, addr = s.accept()
c.send(b'data')
c.close()
s.close()
Note that the client socket returned is also a instance of StructuredSocket.
# client side
from structsock import StructuredSocket
c = StructuredSocket()
c.connect(('127.0.0.1', 5000))
data = c.recv() # different, no bufsize
print(data.decode())
c.close()
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file structsock-1.2.0.tar.gz.
File metadata
- Download URL: structsock-1.2.0.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
207702f47aa00d850bb0d2d056b15f0df1568875699077033abcd082dcb610ea
|
|
| MD5 |
84db24879e1c12874f81c2138751ca88
|
|
| BLAKE2b-256 |
dec6e9f66a5214e4331ecb3c7088ac6d867056279a420c8f16206080ca2607e5
|
File details
Details for the file structsock-1.2.0-py3-none-any.whl.
File metadata
- Download URL: structsock-1.2.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3167b7399b96ba2fdc0bea31f9621db2487b43e2cfb96acf23384480c7632718
|
|
| MD5 |
595925042941ab994dafc5d28bb52a8e
|
|
| BLAKE2b-256 |
cb7733908e923f3d8193b35f47f7d49c4598c5afa2587bb0b9f5bcb992eafe78
|