Networking Reference
In-Depth Information
Let's take an example to make things clearer. Consider a scenario where we would
like to set up a stock exchange program. There are brokers and they would like to
know how certain stocks are doing in the market. Our publisher is the stock market
and our subscribers are the brokers.
Instead of getting real numbers from stock markets, we will just generate some random
numbers for stock values.
Before jumping into any code, first let's see what the publish-subscribe pattern
looks like.
-
-
-
-
SUB
SUB
SUB
SUB
Subscriber
Subscriber
Subscriber
Subscriber
connect
connect
connect
connect
update
update
update
update
binds
-
PUB
Publisher
The publish-subscribe pattern
The following is the publisher code (server):
/*
* Stock Market Server
* Binds PUB socket to tcp://*:4040
* Publishes random stock values of random companies
*/
#include <string.h>
#include "zmq.h"
 
Search MirCeyron ::




Custom Search