Skip to content

Instantly share code, notes, and snippets.

@easytiger
Created June 14, 2014 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save easytiger/a508ee5d0714c64407af to your computer and use it in GitHub Desktop.
Save easytiger/a508ee5d0714c64407af to your computer and use it in GitHub Desktop.
#include <assert.h>
#include <stdio.h>
#include <nanomsg/nn.h>
#include <nanomsg/pubsub.h>
#include <iostream>
#include <sstream>
#include <assert.h>
#include <stdint.h>
#include <time.h>
#include <ostream>
#include <cstdlib>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main (const int argc, const char **argv)
{
int sock = nn_socket (AF_SP, NN_PUB);
assert (sock >= 0);
assert (nn_bind (sock, "tcp://*:5563") >= 0);
if (argc < 3)
{
cout << "-USAGE: " << argv[0] << " <uint number of iterations> <uint log print modulo>" << endl;
cout << " -e.g. to send 100,000 messages and log every 100: $" << argv[0] << " 100000 100" << endl;
abort();
}
uint64_t loop = atoi(argv[1]);
uint64_t c = 1;
while (c <= loop)
{
std::stringstream ss;
ss << "MESSAGE PAYLOAD OF A NONTRIVAL SIZE KIND OF AND SUCH #" << c;
int rc = nn_send(sock, ss.str().c_str(), ss.str().length(), 0);
if (c % atoi(argv[2]) == 0)
cout << "sent " << ss.str() << " with rc="<< rc << endl;
++c;
}
sleep(5);
nn_shutdown (sock, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment