Skip to content
Tommaso Bertoni edited this page Mar 11, 2017 · 6 revisions

Create and start a server:

IrisServer server = new IrisServer();
server.Start(2200); // Start on port 2200

Create and connect a local node:

// If you have a server and you want to use the same subscription network
IrisServerConfig config = server.GetServerConfig();
// If you just want to communicate locally or on a different local network
IrisServerConfig config = new IrisServerConfig(new IrisPubSubRouter());
IrisLocalNode node = new IrisLocalNode();
node.Connect(config);

Create and connect a node over the network:

IrisClientConfig config = new IrisClientConfig() { Hostname = "127.0.0.1", Port = 2200 };
IrisClientNode node = new IrisClientNode();
node.Connect(config);

Subscribe to a channel

Task<IDisposableSubscription> asyncSubscriptionRequest = node.Subscribe("worldnews", MyContentHandler);
// The task is resolved when the subscription request is sent over the network stream
IDisposableSubscription subscription = await asyncSubscriptionRequest;

Publish a message

await node.Publish("worldnews", "something good happened");

Unsubscribe from a channel

// If you have a reference to the IDisposableSubscription returned by the
// Subscribe method you can simply write
subscription.Dispose();
// Otherwise you can use the Unsubscribe method
await node.Unsubscribe("worldnews", MyContentHandler);

For more examples and use cases head over to the Iris.NET.Demo project.

Clone this wiki locally