checkNanoSocket

check nanomsg socket

?
void
checkNanoSocket
(
T
)
(
)

Examples

Examples: */ /// set/get option //

1 auto sock = NanoSocket(NanoSocket.Protocol.subscribe);
2 sock.getOption!int(NanoSocket.Option.sendTimeoutMs).shouldEqual(-1);
3 sock.setOption(NanoSocket.Option.sendTimeoutMs, 42);
4 sock.getOption!int(NanoSocket.Option.sendTimeoutMs).shouldEqual(42);

publish/subscribe

1 const uri = "inproc://test_pubsub";
2 auto pub = NanoSocket(NanoSocket.Protocol.publish, BindTo(uri));
3 auto sub = NanoSocket(NanoSocket.Protocol.subscribe, ConnectTo(uri));
4 sub.setOption(NanoSocket.Option.subscribeTopic, "foo");
5 
6 // messages that start with the subscription topic should be received
7 pub.send("foo/hello");
8 sub.receive(No.blocking).shouldEqual("foo/hello");
9 
10 // but not messages that don't
11 pub.send("bar/oops");
12 sub.receive(No.blocking).shouldBeEmpty;
13 
14 // after unsubscribing, messages are no longer received
15 sub.setOption(NanoSocket.Option.unsubscribeTopic, "foo");
16 pub.send("foo/hello");
17 sub.receive(No.blocking).shouldBeEmpty;

request/response

1 import std.concurrency: spawnLinked, send;
2 
3 const uri = "inproc://test_reqrep";
4 const requester = NanoSocket(NanoSocket.Protocol.request, ConnectTo(uri));
5 
6 enum timeoutMs = 50;
7 requester.setOption(NanoSocket.Option.receiveTimeoutMs, timeoutMs);
8 
9 auto tid = spawnLinked(&responder, uri, timeoutMs);
10 requester.send("shake?").shouldEqual("shake? yep!");
11 tid.send(Stop());

Meta