Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

structsock-1.2.0.tar.gz (2.7 kB view hashes)

Uploaded Source

Built Distribution

structsock-1.2.0-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page