socket_comm

Description

Server/client communication via TCP sockets. The module implements TCP communication between a daemon-like Server and a simple Client.

The Server class is meant to be run as a daemon-like app. The user should override the create_parser() method to define the daemon behaviour upon reception of a message from a Client. The base class provides support for the message ‘quit’, which will terminate the daemon. Any other message will be met with a help-like reply.

The Client class communicates with the Server sending a text string.

The ArgumentParser class and MessageError exception are necessary to override some unwanted default behaviour of the argparse library.

The module is based upon this tutorial.

lab_utils.socket_comm.buffer_size

Maximum length of a transmitted messages

Type

int, 1024

Classes

ArgumentParser

Modifies some annoying behaviours of the argparse library.

Client

Simple TCP client to communicate with a running Server.

Server

Daemon-like TCP server.

Exceptions

MessageError

Invalid message.