git-svn-id: svn://elaine/murooma/trunk@4 d8a302eb-03bc-478d-80e4-98257eca68ef

This commit is contained in:
(no author) 2014-06-24 18:06:38 +00:00
parent 798146dda9
commit 429490e2e3

53
server.cpp Normal file
View file

@ -0,0 +1,53 @@
//
// Weather update server in C++
// Binds PUB socket to tcp://*:5556
// Publishes random weather updates
//
// Olivier Chamoux <olivier.chamoux@fr.thalesgroup.com>
//
#include <zmq.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
using namespace std;
int main () {
// Prepare our context and publisher
zmq::context_t context (1);
zmq::socket_t publisher (context, ZMQ_PUB);
publisher.bind("tcp://0.0.0.0:123458");
// publisher.bind("ipc://weather.ipc");
// Initialize random number generator
srandom ((unsigned) time (NULL));
size_t idx(0);
const int size(1024);
char msg[size];
char c;//[2];
// msg[0] = '0';
// int fd;
// fd = open("stdin", O_RDONLY|O_BINARY, 0);
while (!cin.get(c).eof())
{
// read(fd, &msg[0], size);
msg[idx++] = c;
if (idx == size)
{
zmq::message_t message(size);
memcpy(message.data(), &msg[0], size);
// snprintf ((char *) message.data(), size, "%05d %d", zipcode, c);
// message.data()[0] = c;
publisher.send(message);
idx = 0;
// msg[0] = '0';
}
}
return 0;
}