-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_send.cpp
More file actions
72 lines (58 loc) · 2 KB
/
main_send.cpp
File metadata and controls
72 lines (58 loc) · 2 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "stdafx.h"
#include "Fault.h"
#include "RemoteId.h"
#include "RemoteDataPoint.h"
#ifdef RAPID_JSON
#include "RemoteNotificationJson.h"
#endif
#include "UdpDelegateSend.h"
#include "DelegateLib.h"
#include <iostream>
#include <conio.h>
// main.cpp
// @see https://www.codeproject.com/Articles/5262271/Remote-Procedure-Calls-using-Cplusplus-Delegates
// David Lafreniere, Mar 2020.
//
// @see https://www.codeproject.com/Articles/1160934/Asynchronous-Multicast-Delegates-in-Cplusplus
// David Lafreniere, Dec 2016.
using namespace DelegateLib;
using namespace std;
//------------------------------------------------------------------------------
// main
//------------------------------------------------------------------------------
int main(void)
{
BOOL result = AfxWinInit(GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0);
ASSERT_TRUE(result == TRUE);
result = AfxSocketInit(NULL);
ASSERT_TRUE(result == TRUE);
UdpDelegateSend::GetInstance().Initialize();
// Create a stream to hold send data
stringstream ss(ios::in | ios::out | ios::binary);
// Create a send remote delegate
auto sendDataPointDelegate =
MakeDelegate<RemoteDataPoint&>(UdpDelegateSend::GetInstance(), ss, REMOTE_DATA_POINT_ID);
// See RapidJSON_Readme.txt
#ifdef RAPID_JSON
auto sendNotificationDelegate =
MakeDelegate<int, RemoteNotificationJson&>(UdpDelegateSend::GetInstance(), ss, REMOTE_NOTIFICATION_JSON_ID);
#endif
cout << "Press any key to exit program." << endl;
int x = 1;
int y = 1;
int count = 1;
while (!_kbhit())
{
// Send data point to remote system
RemoteDataPoint dataPoint(x++, y++);
sendDataPointDelegate(dataPoint);
#ifdef RAPID_JSON
// Send notification to remote system
RemoteNotificationJson notification("RPC using UDP and JSON!");
notification.GetPoints().push_back(RemoteDataPointJson(x, y));
sendNotificationDelegate(count++, notification);
#endif
Sleep(5);
}
return 0;
}