Replace ICalculator with IServerMethods

Rename the server implementation and update client/server pipes to use
the shared server-methods interface. Move PipeConstants alongside it and
log “Client started.” during client startup.
This commit is contained in:
Matthias Heil
2026-11-10 10:42:57 +01:00
parent 23c2a9ea16
commit d618bac679
4 changed files with 8 additions and 8 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ Log("Client started.");
string pipeName = $"PipeDemo-{Environment.ProcessId}-{Guid.NewGuid():N}"; string pipeName = $"PipeDemo-{Environment.ProcessId}-{Guid.NewGuid():N}";
Process? serverProcess = null; Process? serverProcess = null;
PipeClient<ICalculator> client = null!; PipeClient<IServerMethods> client = null!;
try try
{ {
@@ -154,7 +154,7 @@ async Task StartServerAndConnectAsync(string pipeName)
}; };
serverProcess = process; serverProcess = process;
client = new PipeClient<ICalculator>(new JsonFieldsPipeSerializer(), pipeName); client = new PipeClient<IServerMethods>(new JsonFieldsPipeSerializer(), pipeName);
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
await client.ConnectAsync(cts.Token); await client.ConnectAsync(cts.Token);
} }
+2 -2
View File
@@ -9,10 +9,10 @@ Console.WriteLine($"Server started. Pipe: {pipeName}");
// Exceptions in handler methods are caught by PipeMethodCalls and sent to the client // Exceptions in handler methods are caught by PipeMethodCalls and sent to the client
// (client receives PipeInvokeFailedException with the server exception details). // (client receives PipeInvokeFailedException with the server exception details).
var server = new PipeServer<ICalculator>( var server = new PipeServer<IServerMethods>(
new JsonFieldsPipeSerializer(), new JsonFieldsPipeSerializer(),
pipeName, pipeName,
() => new Calculator()); () => new ServerMethods());
await server.WaitForConnectionAsync(); await server.WaitForConnectionAsync();
Console.WriteLine("Client connected."); Console.WriteLine("Client connected.");
@@ -1,10 +1,10 @@
using System.Collections.Concurrent; using ClientServerShared;
using System.Collections.Concurrent;
using System.Numerics; using System.Numerics;
using ClientServerShared;
namespace Server; namespace Server;
public class Calculator : ICalculator public class ServerMethods : IServerMethods
{ {
public int Add(int a, int b) => a + b; public int Add(int a, int b) => a + b;
@@ -2,7 +2,7 @@ using System.Numerics;
namespace ClientServerShared; namespace ClientServerShared;
public interface ICalculator public interface IServerMethods
{ {
int Add(int a, int b); int Add(int a, int b);
Vector3 AddVector(Vector3 a, Vector3 b); Vector3 AddVector(Vector3 a, Vector3 b);