![]() |
PIP 5.6.1
Platform-Independent Primitives
|
The ClientServer module provides a TCP server that accepts connections and manages per-client objects, and an active client that connects to a server. All in the PIClientServer namespace.
PIClientServer::Server listens on an address (e.g. listenAll(port) for all interfaces). For each accepted connection the server creates a PIClientServer::ServerClient. You can override the client type and handle client lifecycle (e.g. data received, disconnected). Use getMaxClients() / setMaxClients() to limit simultaneous connections. listen(addr) starts listening, stopServer() stops the server, closeAll() closes all current clients.
PIClientServer::ServerClient is the server-side representation of one connected client. The server creates and owns these objects. Override aboutDelete() if you need cleanup before the client is removed. Use the base API (ClientBase) to send and receive data on the connection.
PIClientServer::Client is the active client: it connects to a remote server (address/port). After connecting you use the same send/receive API as on the server side. Connect, exchange data, then disconnect when done.
Server: construct Server, optionally set max clients and callbacks, call listen() or listenAll(port). Handle client events (new client, data, disconnect) in your overrides or via the provided hooks. Client: construct Client, connect to server address, send/receive, disconnect.
See piclientserver_server.h, piclientserver_client.h, piclientserver_client_base.h for the full API.