-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.cpp
More file actions
36 lines (31 loc) · 1023 Bytes
/
server.cpp
File metadata and controls
36 lines (31 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "communication.h"
#include "server.h"
#include <chrono>
#include <iostream>
#include <thread>
void perform(int nseconds, std::string const& endpoint)
{
std::cout << "Welcome to perform()" << std::endl;
// Prepare our context and socket
std::cout << "Create context" << std::endl;
zmq::context context;
std::cout << "Create socket" << std::endl;
zmq::socket publisher = context.socket(ZMQ_PUB);
std::cout << "Connect socket to endpoint" << std::endl;
publisher.connect(endpoint.c_str());
std::cout << "Enter the waiting loop" << std::endl;
#pragma omp parallel for
for (int i = 0; i < 5; ++i)
{
std::cout << "Waiting for " << nseconds << " s" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds{nseconds});
#pragma omp critical
{
std::cout << "Sending loop index " << i << std::endl;
publisher.send("%1d", i);
}
}
std::cout << "Sending end signal" << std::endl;
publisher.send(">>END" );
std::cout << "Bye... :-)" << std::endl;
}