Server API¶
CLICK Modbus TCP simulator and server utilities.
pyclickplc.ClickServer ¶
Modbus TCP server simulating a CLICK PLC.
bound_port
property
¶
Return the port the server listens on, or None when it is not listening.
It is None whenever is_running() returns False.
list_clients ¶
Return the currently connected Modbus TCP clients.
disconnect_client ¶
Disconnect the client with this client_id.
Return True if that client was connected, and False otherwise.
disconnect_all_clients ¶
Disconnect all connected clients and return how many were closed.
start
async
¶
Start the Modbus TCP server.
If the server stopped listening on its own (is_running() returns False although you
did not call stop()), start() closes the old listener and its clients, then
listens again. If you cancel start() before it returns, the server stays stopped.
If you call stop() while start() is still running, start() returns without
listening.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
The server is already listening, can't listen on its host and port, or runs on another event loop. |
stop
async
¶
Stop the server, closing every connection.
If you cancel stop(), the server has still stopped. A client that has not closed
after 1 s is dropped. If you call stop() while start() is running, the server
stops what that start() opens.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
The server runs on another event loop. Stop it on that loop. |
serve_forever
async
¶
Start the server and block until stop().
If the server stopped listening on its own and start() replaces the listener, this
call keeps serving. If you cancel this call, the server stops.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
The server is already listening, can't listen on its host and port,
runs on another event loop, or stopped listening on its own and |
pyclickplc.MemoryDataProvider ¶
Bases: AddressNormalizerMixin
In-memory DataProvider for testing and simple use cases.
pyclickplc.ServerClientInfo
dataclass
¶
Connected client metadata exposed by ClickServer.
pyclickplc.run_server_tui
async
¶
run_server_tui(
server: ClickServer,
*,
prompt: str = "clickserver> ",
input_fn: Callable[[str], str] | None = None,
output_fn: Callable[[str], None] | None = None,
) -> None
Run a basic interactive command loop for a ClickServer.