Sending messages to many hosts at once
There might be a case when you'd like to send a single message to multiple hosts at the same time. A typical example of such a situation can be a chat application. The ZeroMQ library solves this problem with the Publisher-Subscriber model, which is similar to a well-known multicast. Multiple types of messages can be divided into topics identified by a simple string value.
Do note that with the Publisher-Subscriber model, you can send messages only from the publisher to the subscriber, not the other way round.
Getting ready
For this recipe, you'll be using one publisher part and at least one subscriber. You can run more subscriber instances to see the effect of this network model.
How to do it…
This recipe will be divided into two parts, one for the publisher and the other for the subscriber.
The publisher part
Let's take a look at the publisher recipe:
First you'll need to prepare the ZeroMQ socket for the publisher:
local zmq = require 'zmq' local context...