Skip to content

A simple module to encapsulate the built-in socket with struct.pack.

License

Notifications You must be signed in to change notification settings

origamizyt/StructuredSocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

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.)

Version: 1.0 (Final Release Perhaps)

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()

About

A simple module to encapsulate the built-in socket with struct.pack.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages