Add interactive ClientConsole example to Python, C# and C SDKs#43
Add interactive ClientConsole example to Python, C# and C SDKs#43nevstop merged 2 commits intoDev_2026Q2from
Conversation
Agent-Logs-Url: https://github.com/NEVSTOP-LAB/CSM-TCP-Router-App/sessions/ca3628f9-8283-448f-8789-d860c873c1dc Co-authored-by: nevstop <8196752+nevstop@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds an interactive clientConsole REPL example to the Python, C#, and C SDKs to provide a consistent, cross-language console for connecting to a CSM-TCP-Router server and issuing common commands.
Changes:
- Added new interactive REPL examples for Python (
client_console.py), C# (examples/ClientConsole), and C (client_console.c). - Registered the new C# example project in
CsmTcpRouter.sln. - Added a new C example target (
client_console) to the C SDK CMake build.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| SDK/python/examples/client_console.py | New Python REPL console example (stdin-driven) with unified commands/output. |
| SDK/csharp/examples/ClientConsole/Program.cs | New C# REPL console implementation using the C# SDK APIs. |
| SDK/csharp/examples/ClientConsole/ClientConsole.csproj | New C# example project definition referencing the SDK project. |
| SDK/csharp/CsmTcpRouter.sln | Adds the new C# example project to the solution and build configs. |
| SDK/c/examples/client_console.c | New C REPL console example using the C SDK APIs and callbacks. |
| SDK/c/CMakeLists.txt | Adds client_console executable target under CSM_BUILD_EXAMPLES. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| def main(argv: list[str]) -> int: | ||
| host = argv[1] if len(argv) > 1 else DEFAULT_HOST | ||
| port = int(argv[2]) if len(argv) > 2 else DEFAULT_PORT |
There was a problem hiding this comment.
port = int(argv[2]) will raise ValueError and abort the program if the user passes a non-integer port (e.g. python client_console.py localhost abc). Consider catching this and printing an Error: invalid port '<value>' message (and returning nonzero), similar to the C example’s validation.
| port = int(argv[2]) if len(argv) > 2 else DEFAULT_PORT | |
| if len(argv) > 2: | |
| try: | |
| port = int(argv[2]) | |
| except ValueError: | |
| print(f"Error: invalid port '{argv[2]}'") | |
| return 1 | |
| else: | |
| port = DEFAULT_PORT |
| public static int Main(string[] args) | ||
| { | ||
| string host = args.Length > 0 ? args[0] : DefaultHost; | ||
| int port = args.Length > 1 ? int.Parse(args[1]) : DefaultPort; |
There was a problem hiding this comment.
int.Parse(args[1]) will throw FormatException/OverflowException on invalid input and terminate the console. Consider using int.TryParse (and range-checking 1–65535) to print a friendly Error: invalid port '<value>' message and exit cleanly.
| int port = args.Length > 1 ? int.Parse(args[1]) : DefaultPort; | |
| int port = DefaultPort; | |
| if (args.Length > 1) | |
| { | |
| if (!int.TryParse(args[1], out port) || port < 1 || port > 65535) | |
| { | |
| Console.WriteLine($"Error: invalid port '{args[1]}'"); | |
| return 1; | |
| } | |
| } |
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/NEVSTOP-LAB/CSM-TCP-Router-App/sessions/1a565ac6-daf6-4291-8c0c-b3444c37d8ba Co-authored-by: nevstop <8196752+nevstop@users.noreply.github.com>
Applied port validation in both the Python and C# |
SDK/python/examples/client_console.py(Python SDK)SDK/csharp/examples/ClientConsole/{ClientConsole.csproj,Program.cs}(C# SDK) and register inCsmTcpRouter.slnSDK/c/examples/client_console.c(C SDK) and register inSDK/c/CMakeLists.txtcsm>prompt, same command set, same output formattingportCLI argument in Python and C# (matching the C example) — printError: invalid port '<value>'and exit 1 on non-integer or out-of-range input