Server¶
Description
-
class
lab_utils.socket_comm.
Server
(config_file: Optional[str] = None, pid_file_name: Optional[str] = None, host: Optional[str] = None, port: Optional[int] = None)[source]¶ Daemon-like TCP server. The server connects to the specified
host
andport
and locks aPID file
to ensure it is the only instance running.If successful, the server will then listen indefinitely, waiting for a client to connect. Upon connection, a
message
is received and passed to theparser
. If the message is valid, the parser will call the respective method. The base class provides only thequit()
method; users should create new methods suitable for their needs. These methods should always set an appropriatereply
, which will be then sent back to the client.If a message is not valid (i.e. the parser does not support it), an error message and a complete help string is sent back to the client. The help string by the
argparse
library is not complete and hence is overridden by theArgumentParser.full_help()
method.Attributes
TCP binding address.
Left delimiter
Left delimiter
Host address.
LockFile
object.Single
CustomLogger
for the whole class.TCP connection queue.
Message from the client.
Container to hold message options.
Argument parser.
The PID file name
Connection port.
Internal flag to stop the daemon.
Parsing pattern.
Reply to the client.
Connection socket.
Socket time-out, used for Ctrl+C handling
Argument subparser
Methods
Initializes and runs the
Server
object.Releases the PID lock file and the TCP socket.
Loads the server configuration from a file.
Configures the message
parser
, which will call the appropriate method upon reception of a message.Locks a PID file to ensure that a single instance of the server is running.
User-defined task example.
Starts the server.