snapcast/server.cpp
(no author) 1c4dc63a16 xxx
git-svn-id: svn://elaine/murooma/trunk@7 d8a302eb-03bc-478d-80e4-98257eca68ef
2014-06-24 20:23:42 +00:00

58 lines
1.2 KiB
C++

//
// 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>
#include <sys/time.h>
using namespace std;
const int size(1024);
struct Chunk
{
timeval timestamp;
char payload[size];
};
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");
// Initialize random number generator
size_t idx(0);
char c;//[2];
Chunk chunk;
while (!cin.get(c).eof())
{
if (idx == 0)
gettimeofday(&chunk.timestamp, 0);
// read(fd, &msg[0], size);
chunk.payload[idx++] = c;
if (idx == size)
{
zmq::message_t message(sizeof(Chunk));
memcpy(message.data(), &chunk, sizeof(Chunk));
// snprintf ((char *) message.data(), size, "%05d %d", zipcode, c);
// message.data()[0] = c;
publisher.send(message);
idx = 0;
// msg[0] = '0';
}
}
return 0;
}