Module azcam.sockets

azcam.sockets contains azcam's SocketInterface class used by many interfaces.

Classes

class SocketInterface (host: str = '', port: int = 0)

The azcam socket server interface.

Create socket connection instance.

Args

host
host name of remote computer.
port
port number of server on remote computer.

Instance variables

var connected

true when connection is active

var host

host name or IP address of remote server

var last_command

last command send to server

var last_response

last response from server

var lock

thread lock

var port

port number of remote server

var reopen

true to try reopening socket a reset socket when trying to connect

var socket

socket instance

var terminator

termination string for commands

var timeout

connection timeout in seconds

Methods

def close(self) ‑> None

Close the socket connection to the server.

def command(self, command: str, terminator: str = '\n') ‑> list

Sends a command to the server and receives a reply back.

Args

command
command string to send
terminator
termination string to append the command

Returns

tokenized list of the server's reply.

def open(self) ‑> bool

Open a socket connection to the server. Creates the socket and makes a connection.

Returns

True if socket is already open or if it is opened here.

def recv(self, length: int = -1, terminator: str = '\n') ‑> str

Receives a reply from a server. Terminates socket read when length bytes are received or when the terminator is received.

Args

length
number of bytes to receive. -1 means receive through terminator.
terminator
terminator string.
def send(self, command: str, terminator: str = '\n') ‑> None

Send a command string to the server.

Args

command
command string to send
terminator
termination string to append the command
def set_timeout(self, timeout: float = -1.0) ‑> None

Set the receive timeout for socket connection.

Args

timeout
timeout value in seconds. <0 means use current value, =0 means no timeout.
def test(self) ‑> str

Sends and receives a test message over the socket connection.