Networking Reference
In-Depth Information
In this case, the output will be something similar to the following:
Collecting stock information from the server.
Company101 950
Company10 707
Company101 55
Company101 343
Company10 111
Company1 651
Company10 287
Company101 8
Company1 889
Company101 536
Our subscriber code explicitly says that we want to see the results of Company1 .
However, the publisher sends us the results of Company10 and Company101 as
well. This is certainly not what we want. We need to solve this small issue.
We may want to do some dirty hacking to get what we want but using a delimiter
is a much simpler solution for it.
We need to make some changes both in the publisher and the subscriber code
and we will filter the company names using a delimiter.
The following is our updated publisher code that ixes the previous problem.
Have a look at the highlighted line to see how we can use a delimiter to send
the message to the subscribers:
//
// Stock Market Server
// Binds PUB socket to tcp://*:4040
// Publishes random stock values of random companies
//
#include <stdlib.h>
#include <string.h>
#include "zmq.h"
int main (int argc, char const *argv[]) {
void* context = zmq_ctx_new();
void* publisher = zmq_socket(context, ZMQ_PUB);
 
Search MirCeyron ::




Custom Search