diff --git a/client.cpp b/client.cpp new file mode 100644 index 00000000..7f92b3c3 --- /dev/null +++ b/client.cpp @@ -0,0 +1,46 @@ +// +// Weather update client in C++ +// Connects SUB socket to tcp://localhost:5556 +// Collects weather updates and finds avg temp in zipcode +// +// Olivier Chamoux +// +#include +#include +#include + +int main (int argc, char *argv[]) +{ + zmq::context_t context (1); + + // Socket to talk to server +// std::cout << "Collecting updates from weather server…\n" << std::endl; + zmq::socket_t subscriber (context, ZMQ_SUB); + subscriber.connect("tcp://192.168.0.2:123458"); + // Subscribe to zipcode, default is NYC, 10001 + const char* filter = ""; + subscriber.setsockopt(ZMQ_SUBSCRIBE, filter, strlen(filter)); + + // Process 100 updates + int update_nbr; + long total_temp = 0; + const size_t size(1024); + char msg[size]; +// for (update_nbr = 0; update_nbr < 100; update_nbr++) { + while (1) + { + zmq::message_t update; + subscriber.recv(&update); +// std::cerr << "received\n"; +// std::istringstream iss(static_cast(update.data())); +// iss >> zipcode >> relhumidity; + memcpy(&msg[0], update.data(), size); +// std::cout << "update\n"; + for (size_t n=0; n