C#C
C#13mo ago
ero

Client/Server communication with Named Pipes

Most relevant code: https://gist.github.com/just-ero/a9bb60192a7cc090cb9055dc39770139

Context: I'm reading some information from Mono-based processes (mainly Unity games). For this, I use injection to call the Mono API. I have a client sending request codes and payloads to the server in the injected DLL, which sends response payloads.

Unfortunately, I feel like I've made quite some missteps in designing this process. For example:
  • I cannot send a "failure" response; I simply send a response payload with default values,
  • I cannot log,
  • Request codes are not tightly coupled with their respective request payloads,
  • When the client side does not shut down gracefully, the server side does not shut down (because IsConnected is never set to false),
  • The server library has to implement the loop for listening manually, I'd like that to be part of the server class itself.
In general, I feel like I went a bit too far with the amount of inheritance I use for the servers. I abstracted the servers so much that I only return payloads instead of result-type values (even though I do have a Result type).
I would like some help in making this whole system more robust and more intuitive to use and expand upon. I would like a way to add logging (ideally in the form [ServerName] [Method] Actual Log). I would like to shut down (or halt) the server when the client does not shut down gracefully. And I would like someone to look over my ApiSerializer class to spot anything that can be written better. The entire way I exchange data feels very opaque and convoluted (I even get confused myself).

I'm on .NET Standard 2.0 for all of this, so a lot of features simply aren't available to me.
Was this page helpful?