This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
RobotClient is a .NET 8.0 TCP client simulator for a robotic arm control system. It creates multiple concurrent TCP connections to a server, simulating robotic arm clients that can send/receive control commands and status messages.
# Build the project
dotnet build
# Run with default settings (1 client, connects to 127.0.0.1:2000)
dotnet run
# Run with custom options (format: key=value)
dotnet run -- count=5 host=192.168.1.100 serverport=3000 localport=50000 reconnect=false
# Build Docker image
docker build -t robot-client .
# Run in Docker
docker run -it robot-client
| Option | Default | Description |
|---|---|---|
count |
1 | Number of client connections to create |
host |
127.0.0.1 | Server host address |
serverport |
2000 | Server port |
localport |
62312 | Starting local port (each client uses localport + clientId) |
reconnect |
true | Enable automatic reconnection |
reconnectinterval |
5000 | Reconnect delay in milliseconds |
maxreconnect |
-1 | Max reconnect attempts (-1 = infinite) |
The entire application is contained in Program.cs using C# top-level statements. The architecture follows a multi-client concurrent pattern:
ClientOptions (line 358-397): Configuration parser that processes command-line arguments into a strongly-typed options object.
RunClientAsync (line 23-50): Entry point for each client. Binds to a local port, establishes initial connection, spawns a background listener with reconnection logic, and sends initialization commands.
ConnectAsync (line 52-67): Low-level TCP connection using Socket with explicit local port binding.
RunWithReconnectAsync (line 69-134): Wrapper around the message listener that handles automatic reconnection with configurable limits and delays.
ListenServerMessagesAsync (line 181-234): Continuous receive loop that buffers incoming data and parses framed messages. Properly cleans up sockets on disconnect.
TryReadFramedMessages (line 236-293): Parses messages using <START>content<END> framing protocol. Handles partial messages and buffers incomplete data. Contains simulated robot commands:
Pickbattery,1 → Simulates picking operation (5 seconds)Putbattery,1 → Simulates placing operation (5 seconds)clientId:message (e.g., 1:Status). Type exit to quit.Each client sends these commands on connection/startup:
1. Homed → Wait 500ms
2. Runmode,2 → Wait 500ms
3. Armobject,0 → Wait 500ms
4. Controlmode,1
All messages use the frame format: <START>message<END>
<START> is discardedConcurrentDictionary<int, Socket> tracks active client connectionsfinally blocks to prevent resource leaks