nebula
nebula
CC#
Created by nebula on 5/8/2025 in #help
✅ Issue with try/catch block
No description
16 replies
CC#
Created by nebula on 5/6/2025 in #help
Learning C#! Looking for a "conventional" way to accomplish persistent network connections.
Hi! I'm learning C#, been at it for a couple days, I have a lot of experience with Python but I want to try something new. Looking for help on good practice! My goal is to create a Win UI 3 app that communicates with a server over ssh with the SSH.NET library. I want the connection to remain open and ready for new requests without going through the slow initialization process unless it's being opened for the first time or the connection is interrupted due to network problems. Through the ssh connection I wish to communicate with an HTTP server that is not available publicly. And also run shell commands and capture their output. The library offers facilities for both of these use cases, but I'm searching for a way to cleanly manage them. I'm a bit lost with C# conventions in general! In my "scratchpad" code I have set a private variable in the Program object, thinking that storing it here would be the best way to go about this. Here is some very simple code I have written that works outside of a GUI (haven't gotten that far yet). I wish to avoid calling the Connect method in future code and just want a managed connection I can always call methods on and get new data or communicate to the HTTP server. https://git.tilde.town/nebula/sshnet/src/branch/main/sshnet/Program.cs I am wondering if this is conventional, or what a better strategy may be. I will also need to have ports forwarded and kept open. How should I store these and maintain the connection in a way that works well with a GUI app that is kept open?
10 replies