Created
January 25, 2011 11:53
-
-
Save drbobbeaty/794827 to your computer and use it in GitHub Desktop.
Simple SUB Connection Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// System Headers | |
#include <iostream> | |
#include <stdio.h> | |
#include <string> | |
#include <stdint.h> | |
#include <sys/time.h> | |
// Third-Party Headers | |
#include <zmq.hpp> | |
// Other Headers | |
// Forward Declarations | |
// Public Constants | |
// Public DataTypes | |
// Public Data Constants | |
/** | |
* This is the main test frame -- open up a ZMQ socket to the right | |
* URLs and listen to what's being transmitted. Simple. | |
*/ | |
int main(int argc, char *argv[]) { | |
bool error = false; | |
// make the ZMQ Context and Socket for what we need to "hear" | |
zmq::context_t *mContext = NULL; | |
if (!error) { | |
mContext = new zmq::context_t(1); | |
if (mContext == NULL) { | |
error = true; | |
std::cout << "could not create the ZMQ context" << std::endl; | |
} | |
} | |
zmq::socket_t *mSocket = NULL; | |
if (!error) { | |
mSocket = new zmq::socket_t(*mContext, ZMQ_SUB); | |
if (mSocket == NULL) { | |
error = true; | |
std::cout << "could not create the ZMQ socket" << std::endl; | |
} else { | |
// make sure we subscribe to all messages we get | |
mSocket->setsockopt(ZMQ_SUBSCRIBE, "", 0); | |
} | |
} | |
// verify it's all initialized OK | |
if (!error) { | |
std::cout << "Initialization complete." << std::endl; | |
} | |
// now let's connect to the URLs we need to listen to | |
if (!error) { | |
mSocket->connect("epgm://eth0;239.22.3.1:11111"); | |
} | |
/** | |
* At this point we'd like to do something with the messages... | |
* but that's not at the issue right now. | |
*/ | |
// clean it all up | |
if (mSocket != NULL) { | |
delete mSocket; | |
mSocket = NULL; | |
} | |
if (mContext != NULL) { | |
delete mContext; | |
mContext = NULL; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment