From a7ff1b815987b0c1b3ded5701845e0eb52f0592c Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Tue, 14 Jul 2020 21:32:36 -0400 Subject: Added pubsub methods Add socket:subscribe() and socket:unsubscribe() for the pub/sub protocol. --- spec/startup_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'spec') diff --git a/spec/startup_spec.lua b/spec/startup_spec.lua index 45fa996..dacf9e9 100644 --- a/spec/startup_spec.lua +++ b/spec/startup_spec.lua @@ -80,4 +80,17 @@ describe("nng",function() assert(avg > 0.4) assert(avg < 0.6) end) + it("should be able to use publish and subscribe sockets to transfer information", function() + local s1 = assert(nng.pub0_open()) + local s2 = assert(nng.sub0_open()) + local s3 = assert(nng.sub0_open()) + assert(s1:listen("ipc:///tmp/pub.ipc")) + assert(s2:subscribe("")) + assert(s3:subscribe("")) + assert(s2:dial("ipc:///tmp/pub.ipc")) + assert(s3:dial("ipc:///tmp/pub.ipc")) + assert(s1:send("hello 1")) + assert(s2:recv() == "hello 1") + assert(s3:recv() == "hello 1") + end) end) -- cgit v1.2.3-70-g09d2