ClientServerPair¶
-
class
lsst.ts.MTMount.
ClientServerPair
(name, client_host, client_port, server_host, server_port, log, connect_client=True, connect_callback=None)¶ Bases:
object
A TCP/IP client and server combined.
This class exists because Tekniker’s OperationManager software connects to each component using a client and server pair of sockets. The client only writes data and the server only reads data. See
Communicator
for a higher level abstraction.Parameters: - name :
str
Name used for error messages.
- client_host :
str
IP address for the output client socket.
- client_port :
int
IP port for the output client socket.
- server_host :
str
orNone
IP address for the input socket server. If
None
then use all interfaces.- server_port :
int
IP port for the input socket server. If 0 then use a random port.
- log :
logging.Logger
Logger.
- connect_client :
bool
Connect the client at construction time?
- connect_callback : callable or
None
Synchronous function to call when a connection is made or dropped. It receives one argument: this ClientServerPair.
Notes
Attributes
client_host
: client host name, astr
.client_port
: client port, anint
.client_writer
: client socket writer, anasyncio.StreamWriter
, orNone
if not connected.client_reader
: client socket reader, anasyncio.StreamReader
orNone
if not connected.connect_task
(only available ifconnect_client
true): anasyncio.Task
that is set done when connected.
Attributes Summary
client_connected
Is the client connected? connect_retry_interval
Interval between client connection retries (sec). connected
Are both the client and server connected? server_connected
Is the server connected? server_host
server_port
server_reader
Server reader, an asyncio.StreamReader
orNone
if not connected.server_writer
Server writer, an asyncio.StreamWriter
orNone
if not connected.Methods Summary
call_connect_callback
(*args, **kwargs)Call the connect_callback if it exists. close
()Close both the server and the client, to clean up when finished. close_client
()Close the client. connect
([port])Connect the client socket and wait for a connection to the server. wait_server_port
()Wait for the server to start, then return the port. Attributes Documentation
-
client_connected
¶ Is the client connected?
-
connect_retry_interval
= 0.1¶ Interval between client connection retries (sec).
-
connected
¶ Are both the client and server connected?
-
server_connected
¶ Is the server connected?
-
server_host
¶
-
server_port
¶
-
server_reader
¶ Server reader, an
asyncio.StreamReader
orNone
if not connected.
-
server_writer
¶ Server writer, an
asyncio.StreamWriter
orNone
if not connected.
Methods Documentation
-
call_connect_callback
(*args, **kwargs)¶ Call the connect_callback if it exists. Any arguments are ignored.
-
close
()¶ Close both the server and the client, to clean up when finished.
Set the server done_task done.
-
close_client
()¶ Close the client.
Warning: does NOT call the connect_callback.
-
connect
(port=None)¶ Connect the client socket and wait for a connection to the server.
Parameters: Notes
This will wait forever for a connection.
-
wait_server_port
()¶ Wait for the server to start, then return the port.
Useful when you have specified port=0, e.g. for unit tests.
- name :