mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-21 21:16:15 +02:00
git-svn-id: svn://elaine/murooma/trunk@4 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
798146dda9
commit
429490e2e3
1 changed files with 53 additions and 0 deletions
53
server.cpp
Normal file
53
server.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue