Skip to main content

Summary

This module contains a simple base class for handling sockets

The communication protocol has these basic rules:

  • socket based using TCPIP; only one server per port
  • only one client connected at any time. When that client disconnects, another client is allowed to connect.
  • a "packet" is terminated by a line feed (0x0A).
  • a client sends a packet (aka "command") to the server.
  • Alternatively the server may respond with zero, one or more packets (aka "responses")
  • The server cannot initiate a response asynchronously by itself i.e. it must wait for an incoming command to send any packets to the client.
  • the following commands are predefined:
    • "ping" : the server will respond with "pong". The client can use this to confirm that the socket and communication channel are alive and responsive
    • "disconnect" : the server will initiate a disconnect from the current client
    • "shutdown" : the server will disconnect and then shutdown
    • "invalid" - the server has caught an exception when converting the incoming packet to ASCII (e.g. decode ('utf-8'))

More details

  • The server reads the incoming characters from the client one character at a time.
  • Once it sees the 0x0A character, it sets up a string buffer of all ASCII characters seen so far (less the 0x0A) and calls a callback function with that string.
  • The user must define that callback function.
  • The following is up to the user to define:
    • Which incoming commands are legal
    • What response to send if an illegal command is received
    • What response or responses should be sent for all legal commands
    • Determine whether an empty string is a legal command
    • How to handle the scenario when a linefeed needs to be part of a command
    • How to handle non-ASCII scenarios e.g. Unicode or byte strings.

Scripts

Sample code

see the sample directory for a sample client and server. Use doit script to run the sample server.

./doit
  • starts a server as a background process
  • starts a client and sends various commands to the server
  • stops that client
  • starts another client
  • sends some additional commands to the server
  • asks the server to shutdown

Other scripts and files

  • do_doc: generates doxygen
  • do_install: installs python environment
  • do_lint: runs static analysis tools
  • do_publish: publish the python module
  • do_ver: runs verification scripts
  • doit: runs a sample client & server
  • srs.json: holds a list of requirements the client/server must adhere to
  • test_ver.py: run by do_ver to perform verification
  • todo.md known issues to fix/address

Metadata

Release files for socket-oneline 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for socket-oneline 1.2.0
File Size Uploaded
socket_oneline-1.2.0.tar.gz 10.1 kB Details

Release files / socket_oneline-1.2.0.tar.gz

Download URL socket_oneline-1.2.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5f6735454f3f729274ae8524690ec6de459275dcb0d61d17526cca5c321daeb9
BLAKE2b-256 checksum
How to use checksums
d7852dc17b35a1b0887f74d287fab353acd276c1eb61fc59303c0d30b6b7152a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.2.0 This release

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.25

1 release file

0.0.24

1 release file

0.0.23

1 release file

0.0.22

1 release file

0.0.21

1 release file

0.0.20

1 release file

0.0.19

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page