Skip to content

Add interactive ClientConsole example to Python, C# and C SDKs#43

Merged
nevstop merged 2 commits intoDev_2026Q2from
copilot/add-client-console-programs
Apr 28, 2026
Merged

Add interactive ClientConsole example to Python, C# and C SDKs#43
nevstop merged 2 commits intoDev_2026Q2from
copilot/add-client-console-programs

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 28, 2026

  • Add SDK/python/examples/client_console.py (Python SDK)
  • Add SDK/csharp/examples/ClientConsole/{ClientConsole.csproj,Program.cs} (C# SDK) and register in CsmTcpRouter.sln
  • Add SDK/c/examples/client_console.c (C SDK) and register in SDK/c/CMakeLists.txt
  • All three implement an identical REPL: same csm> prompt, same command set, same output formatting
  • Validate port CLI argument in Python and C# (matching the C example) — print Error: invalid port '<value>' and exit 1 on non-integer or out-of-range input

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread SDK/python/examples/client_console.py Outdated

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
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
public static int Main(string[] args)
{
string host = args.Length > 0 ? args[0] : DefaultHost;
int port = args.Length > 1 ? int.Parse(args[1]) : DefaultPort;
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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 uses AI. Check for mistakes.
@nevstop
Copy link
Copy Markdown
Contributor

nevstop commented Apr 28, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 28, 2026

@copilot apply changes based on the comments in this thread

Applied port validation in both the Python and C# client_console examples — non-integer or out-of-range values now print Error: invalid port '<value>' and exit 1, matching the C example. Commit 54470c4.

Copilot AI requested a review from nevstop April 28, 2026 10:13
@nevstop nevstop marked this pull request as ready for review April 28, 2026 10:16
@nevstop nevstop merged commit 0c4fb08 into Dev_2026Q2 Apr 28, 2026
@nevstop nevstop deleted the copilot/add-client-console-programs branch April 28, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants