Skip to content

Faragoz/AF-Client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AF-TCP-Client

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 app branch.

Features

  • 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

Installation

From Source

git clone https://github.com/Faragoz/AF-Client.git
cd AF-Client
pip install -e .

With Development Dependencies

pip install -e ".[dev]"

Quick Start

CLI Test

# Test connection
af-tcp-client --test -H 127.0.0.1 -p 2001

Programmatic Usage

import 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())

Configuration

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.0

Architecture

af_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

Protocol Classes

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"

Development

Install Development Dependencies

pip install -e ".[dev]"

Run Tests

pytest -v

Run Tests with Coverage

pytest --cov=af_client --cov-report=html

Lint Code

ruff check .

Type Check

mypy af_client

Requirements

  • Python >= 3.10
  • af-serializer
  • uvloop >= 0.19.0 (Unix only)

License

MIT License - See LICENSE file for details.

Author

Faragoz - aragon.froylan@gmail.com

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages