-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathudp_producer.cpp
55 lines (45 loc) · 1.44 KB
/
udp_producer.cpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
#include "data_structs.hpp"
#include "service_discovery.h"
#include "udp_multicast_sender.hpp"
#include "container_impl.h"
#include "message_constants.h"
void next_message(vi::Message& m)
{
m.MessageData = rand() % 100 + 1;
m.MessageId = m.MessageId + 1;
m.MessageSize = sizeof(m);
m.MessageType = PAYLOAD_MESSAGE_TYPE;
}
int main(int argc, char *argv[])
{
srand(time(NULL));
printf("UDP Multicast Producer started...\n");
printf("Binding to interface: %s, group: %s, port: %d...\n", VI_INTERFACE_ADDRESS, VI_MULTICAST_GROUP, VI_MULTICAST_PORT);
vi::udp_multicast_sender s;
s.connection().open()
.reuse_address()
.set_nonblocking()
.disable_loopback()
.bind_interface(VI_INTERFACE_ADDRESS);
s.set_target(VI_MULTICAST_GROUP, VI_MULTICAST_PORT);
printf("Begin sending packets...\n");
vi::Message m;
next_message(m);
while(m.MessageId < HIMPL_MAX_ELEMENT_COUNT + 1)
{
if (vi::udp_multicast_sender::send_ok == s.send<vi::Message>(m))
{
next_message(m);
}
}
// send 10 termination messages, just to make sure they've reached recipient
m.MessageType = TERMINATION_MESSAGE_TYPE;
for (int i = 0; i < 10; ++i)
{
m.MessageData = TARGET_DATA_VALUE;
s.send<vi::Message>(m);
}
printf("UDP Multicast Producer finished...\n");
}