Low-latency TCP client module for LabVIEW server communication with AF-Serializer protocol.
Note: This is the minimal TCP communication module extracted from the full application. The complete application with console, benchmarking, and PsychoPy integration is available in the
appbranch.
-
Low-latency TCP communication with optimizations:
- Nagle's algorithm disabled (TCP_NODELAY)
- QoS with DSCP EF for low latency
- Minimal buffer sizes
- Asyncio + uvloop for improved performance
-
Request-response architecture with UUID correlation
-
Protocol classes for communication using AF-Serializer
git clone https://github.com/Faragoz/AF-Client.git
cd AF-Client
pip install -e .pip install -e ".[dev]"# Test connection
af-tcp-client --test -H 127.0.0.1 -p 2001import asyncio
from af_client import TCPClient, Config, EchoCommand
async def main():
config = Config()
config.network.host = "127.0.0.1"
config.network.port = 2001
client = TCPClient(config)
try:
await client.connect()
# Send echo command
cmd = EchoCommand()
cmd.payload = "Hello"
response = await client.send_command(cmd)
print(f"Response: {response.message}")
finally:
await client.disconnect()
asyncio.run(main())Create af_server_config.toml in your working directory:
[network]
host = "127.0.0.1"
port = 2001
timeout = 5.0
buffer_size = 256
enable_nodelay = true
enable_qos = true
heartbeat_interval = 30.0af_server_client/
├── core/
│ ├── tcp_client.py # Asyncio TCP client with uvloop
│ ├── protocol.py # @lvclass command definitions
│ ├── response_handler.py # Request-response correlation
│ └── config.py # TOML configuration loader
├── _mock/
│ └── af_serializer.py # Mock for testing without af-serializer
└── cli.py # Minimal CLI for testing
The client uses AF-Serializer for communication:
from af_client import Protocol, EchoCommand, Response
# General protocol wrapper
protocol = Protocol()
protocol.data = "request-id"
# Echo command for testing
cmd = EchoCommand()
cmd.payload = "test data"
cmd.timestamp = 1234567890.123
# Server response
response = Response()
response.request_id = "request-id"
response.success = True
response.exec_time = 1500.0 # μs
response.message = "OK"pip install -e ".[dev]"pytest -vpytest --cov=af_client --cov-report=htmlruff check .mypy af_client- Python >= 3.10
- af-serializer
- uvloop >= 0.19.0 (Unix only)
MIT License - See LICENSE file for details.
Faragoz - aragon.froylan@gmail.com