[zeromq-dev] ZeroMQ PUB-SUB Help ..!!
Rahul Mathur
srivmuk at gmail.com
Mon Dec 9 10:40:38 CET 2013
All,
I have testpub.cpp and testsub.cpp as below -
---testpub.cpp---
#include <cstdio>
#include <cstdlib>
#include <string>
#include "zmq.hpp"
#include "zmq_utils.h"
using namespace std;
struct MessageStruct {
long UniqueID;
short Pro_ClientIndicator;
char AccountNumber[10];
short ORDERTYPE;
char Symbol[10];
long Volume;
long Price;
short Buy_Sell;
char Status;
} ss_oms_call;
int main (int argc, char *argv[]) {
// Prepare context and publisher
zmq::context_t context (1);
zmq::socket_t pubs (context, ZMQ_PUB);
pubs.bind("tcp://*:5556");
pubs.bind("ipc://ssoms.ipc");
while (1) {
ss_oms_call.UniqueID = 100000001;
ss_oms_call.Pro_ClientIndicator = 1;
ss_oms_call.AccountNumber[0] = '1';
ss_oms_call.AccountNumber[1] = '1';
ss_oms_call.AccountNumber[2] = '2';
ss_oms_call.AccountNumber[3] = '3';
ss_oms_call.AccountNumber[4] = '4';
ss_oms_call.AccountNumber[5] = '5';
ss_oms_call.AccountNumber[6] = 0x20;
ss_oms_call.AccountNumber[7] = 0x20;
ss_oms_call.AccountNumber[8] = 0x20;
ss_oms_call.AccountNumber[9] = 0x20;
ss_oms_call.ORDERTYPE = 0x0000;
ss_oms_call.Symbol[0] = 0x4f;
ss_oms_call.Symbol[1] = 0x4a;
ss_oms_call.Symbol[2] = 0x56;
ss_oms_call.Symbol[3] = 0x4e;
ss_oms_call.Symbol[4] = 0x52;
ss_oms_call.Symbol[5] = 0x32;
ss_oms_call.Symbol[6] = 0x23;
ss_oms_call.Symbol[7] = 0x51;
ss_oms_call.Symbol[8] = 0x20;
ss_oms_call.Symbol[9] = 0x20;
ss_oms_call.Price = 655000;
ss_oms_call.Buy_Sell = 2;
ss_oms_call.Status = 0;
zmq::message_t message(1000);
snprintf ((char *) message.data(), 1000 , "%d %hu %c %d %hu
%c %d %d %hu %c ", ss_oms_call.UniqueID,
ss_oms_call.Pro_ClientIndicator, ss_oms_call.AccountNumber,
ss_oms_call.ORDERTYPE, ss_oms_call.Symbol,
ss_oms_call.Volume, ss_oms_call.Price,
ss_oms_call.Buy_Sell, ss_oms_call.Status);
pubs.send(message);
}
// Messaging Cleanup
return 0;
}
-------
and
-----testsub.cpp-------
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include "zmq.hpp"
#include "zmq_utils.h"
using namespace std;
struct MessageStruct {
long UniqueID;
short Pro_ClientIndicator;
char AccountNumber[10];
short ORDERTYPE;
char Symbol;
long Volume;
long Price;
short Buy_Sell;
char Status;
} ss_oms_call;
int main (int argc, char *argv[]) {
zmq::context_t context (1);
// Socket to talk to server
std::cout << "Collecting updates from Strategy Server.\n" << endl;
zmq::socket_t subscriber (context, ZMQ_SUB);
subscriber.connect("tcp://localhost:5556");
// Subscribe to OFD_OMS_MessageStruct
const char *filter = (argc > 1)? argv [1]: "10001 ";
subscriber.setsockopt(ZMQ_SUBSCRIBE, filter, strlen (filter));
int update_nbr;
long total_temp = 0;
for (update_nbr = 0; update_nbr < 100; update_nbr++) {
zmq::message_t update;
subscriber.recv(&update);
std::istringstream iss(static_cast<char*>(update.data()));
iss >> ss_oms_call.UniqueID >>
ss_oms_call.Pro_ClientIndicator >> ss_oms_call.AccountNumber >>
ss_oms_call.ORDERTYPE >> ss_oms_call.Symbol >>
ss_oms_call.Volume >> ss_oms_call.Price >>
ss_oms_call.Buy_Sell >> ss_oms_call.Status;
}
std::cout << "The Unique ID is .."<< filter <<ss_oms_call.UniqueID<<
std::endl;
std::cout << "The Type of Account is .."<< filter
<<ss_oms_call.Pro_ClientIndicator<< std::endl;
std::cout << "The Account Number is .."<< filter
<<ss_oms_call.AccountNumber<< std::endl;
std::cout << "The ORDER TYPE is .."<< filter
<<ss_oms_call.ORDERTYPE<< std::endl;
std::cout << "The Symbol is .."<< filter <<ss_oms_call.Symbol<<
std::endl;
std::cout << "The Price is .."<< filter <<ss_oms_call.Price<<
std::endl;
std::cout << "The Buy or Sell is .."<< filter
<<ss_oms_call.Buy_Sell<< std::endl;
std::cout << "The Status is .."<< filter <<ss_oms_call.Status<<
std::endl;
return 0;
}
-------------
The compilation for both files (g++ testsub.cpp -o testsub -L/../../lib
-lzmq -lrt) works fine but I don't see any output while executing. The
output should be printed as shown in std::cout of testsub.cpp file.
Please help.
Thanks!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20131209/4a8c7f74/attachment.htm>
More information about the zeromq-dev
mailing list