Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Using Zyan with Named Pipes #1

#1

IpcBinaryProtocol uses named pipes on Windows.
Here is a working sample: ipctest.cs

Server-side:

static void RunServer()
{
	var protocol = new IpcBinaryServerProtocolSetup(IpcPortName);

	using (var host = new ZyanComponentHost(ZyanHostName, protocol))
	{
		host.RegisterComponent<ISampleService, SampleService>();
		Console.WriteLine("Server started. Press ENTER to quit.");
		Console.ReadLine();
	}
}

Client-side:

static void RunClient()
{
	var protocol = new IpcBinaryClientProtocolSetup();
	var url = protocol.FormatUrl(IpcPortName, ZyanHostName);

	using (var conn = new ZyanConnection(url, protocol))
	{
		Console.WriteLine("Connected to server.");
		var proxy = conn.CreateProxy<ISampleService>();
	}
}
  • replies 5
  • views 6.5K
  • likes 1
yallie added the faq label
#2
#3

Testing this out too. Something weird about this reply editor on my phone, where the cursor didn’t go where I expected it.

Thanks again for the reply.

Next question, if I want bidirectional async messaging I assume I will need your example above and then also open the IpcBinaryClient/Server in the reverse direction?

#4

No need to. Try using events for callbacks, something like that:

public interface ISampleService
{
     void Hello();
     event EventHandler Callback;
}

// client-side
var proxy = connection.CreateProxy<ISampleService>();
proxy.Callback += (s, e) => Console.WriteLine("Called by server!");
proxy.Hello();

// server-side
class SampleService : ISampleService
{
    public void Hello()
    {
        Console.WriteLine("Called by client! Firing a callback event");
        Callback.?Invoke(null, EventArgs.Empty); // can't send "this" across the wire, hence sender is null
    }

    public event EventHandler Callback;
}
#5

Cool. Will try that out. Thanks a lot! :laughing:

#6

Here is a better location for the Zyan community: https://gitq.com/zyanfx/Zyan
The current one was created under my user's account instead of the zyanfx org account.