Module azcam.tools.cmdserver
azcam.tools.cmdserver contains the CommandServer class for azcam's socket command interface.
Classes
class CommandServer (port=2402)
-
Main class for cmdserver tool.
CommandServer class to receive and execute client commands over the socket interface. This is a socket server which receives command strings, executes them, and returns a reply string. The server normally runs in a thread so as to not block the command line. Each client which connects runs in its own thread (through the ThreadingTCPServer class) and so operates concurrently. There is no global locking, so this process can be dangerous but it does allows multiple clients to interact simultaneously with azcam, which is important for operations like camera control, telescope movement, temperature readback, instrument control, etc.
Constructor. May be extended, do not override.
Ancestors
- socketserver.ThreadingTCPServer
- socketserver.ThreadingMixIn
- socketserver.TCPServer
- socketserver.BaseServer
Methods
def begin(self, port=-1)
-
Start command server.
def command(self, command: str)
-
Execute a command string received from a client over the command socket. Returns the reply string, always starting with OK or ERROR.
def start(self, port=-1)
-
Starts command server in a thread.
def stop(self, port=-1)
-
Stops command server.
class MyBaseRequestHandler (request, client_address, server)
-
Base class for request handler classes.
This class is instantiated for each request to be handled. The constructor sets the instance variables request, client_address and server, and then calls the handle() method. To implement a specific service, all you need to do is to derive a class which defines a handle() method.
The handle() method can find the request as self.request, the client address as self.client_address, and the server (in case it needs access to per-server information) as self.server. Since a separate instance is created for each request, the handle() method can define other arbitrary instance variables.
Ancestors
- socketserver.BaseRequestHandler
Class variables
var cmdserver
Methods
def finish(self)
-
Called when existing connection is closed.
def handle(self)
-
Called when a connection is made from a client. Starts an infinite loop waiting for new commands. Commands are executed sequentially.
def receive_command(self, currentclient)
-
Receive a string from socket until terminator is found. Returns a string. Returns empty string on error. :param currentclient: client ID for socket ID
def setup(self)
-
Called when new connection made.
class ThreadedTCPServer (server_address, RequestHandlerClass, bind_and_activate=True)
-
Mix-in class to handle each request in a new thread.
Constructor. May be extended, do not override.
Ancestors
- socketserver.ThreadingMixIn
- socketserver.TCPServer
- socketserver.BaseServer
Class variables
var allow_reuse_address