Introduce ServerConnection class in PipeClient to encapsulate server process lifecycle, connection, restart, and cleanup instead of inline Process management. Pass PipeClient<IPipeServerMethods> explicitly to example methods rather than relying on a module-level field. Rename namespace Server to PipeServer in PipeServer project and update corresponding using directives. Update error messages in ServerMethods to English.
22 lines
783 B
C#
22 lines
783 B
C#
using PipeShared;
|
|
using PipeMethodCalls;
|
|
using PipeServer;
|
|
|
|
var pipeName = args.FirstOrDefault(static a => a.StartsWith(PipeConstants.PipeNameArgPrefix, StringComparison.Ordinal))?
|
|
[PipeConstants.PipeNameArgPrefix.Length..] ?? "PipeDemo";
|
|
|
|
Console.WriteLine($"Server started. Pipe: {pipeName}");
|
|
|
|
// Exceptions in handler methods are caught by PipeMethodCalls and sent to the client
|
|
// (client receives PipeInvokeFailedException with the server exception details).
|
|
var server = new PipeServer<IPipeServerMethods>(
|
|
new JsonFieldsPipeSerializer(),
|
|
pipeName,
|
|
() => new ServerMethods());
|
|
|
|
await server.WaitForConnectionAsync();
|
|
Console.WriteLine("Client connected.");
|
|
|
|
await server.WaitForRemotePipeCloseAsync();
|
|
Console.WriteLine("Client disconnected. Server exiting.");
|