Skip to content
bramerdaniel edited this page Oct 5, 2022 · 11 revisions

Here is some general information about how the ConsoLovers.Ipc packages work, and what to expect.

1. How can server and client find each other

As IPC sockets use the file system to address an endpoint, you can specify the file the server and the clients share. On the server side this would look like this.

var server = IpcServer.CreateServer()
         .WithSocketFile(() => @"C:\MySocketFile.txt")
         .Start();

This will allow all clients that know this to connect to the sever. The downside of this method is that your clients would have to know this hardcoded file, and you can only address one server.

To make this more dynamic and allow more than one server, you can use the .Net process to create a socket file per convention.

var server = IpcServer.CreateServer()
         .ForCurrentProcess()
         .Start();

The code above will create a socket file in the temp directory with the file name <ProcessName>.<ProccessId>.uds

Now that the server is up the client only need to find the servers process (or start it if the usecase allows it), and create a client factory for the process.

      var serverProcess = Process.GetProcessesByName("MyServer").FirstOrDefault();

      var clientFactory = IpcClient.CreateClientFactory()
         .ForProcess(serverProcess)
         .Build();

For more delails checkout the links for seting up a server or seting up a client

Clone this wiki locally