-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_recv.cpp
More file actions
64 lines (51 loc) · 1.67 KB
/
main_recv.cpp
File metadata and controls
64 lines (51 loc) · 1.67 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
#include "stdafx.h"
#include "Fault.h"
#include "RemoteId.h"
#include "RemoteDataPoint.h"
#ifdef RAPID_JSON
#include "RemoteNotificationJson.h"
#endif
#include "UdpDelegateRecv.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;
static void RecvDataPointCb(RemoteDataPoint& data)
{
cout << "RemoteDataPoint: " << data.GetX() << " " << data.GetY() << endl;
}
#ifdef RAPID_JSON
static void RecvNotificationJsonCb(int count, RemoteNotificationJson& data)
{
cout << "RemoteNotificationJson: " << count << " " << data.GetMsg() << endl;
}
#endif
//------------------------------------------------------------------------------
// main
//------------------------------------------------------------------------------
int main(void)
{
BOOL result = AfxWinInit(GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0);
ASSERT_TRUE(result == TRUE);
result = AfxSocketInit(NULL);
ASSERT_TRUE(result == TRUE);
UdpDelegateRecv::GetInstance().Initialize();
// Create a receive remote delegate
auto recvDataPointDelegate = MakeDelegate(&RecvDataPointCb, REMOTE_DATA_POINT_ID);
// See RapidJSON_Readme.txt
#ifdef RAPID_JSON
auto recvNotificationDelegate = MakeDelegate(&RecvNotificationJsonCb, REMOTE_NOTIFICATION_JSON_ID);
#endif
cout << "Press any key to exit program." << endl;
while (!_kbhit())
{
Sleep(10);
}
return 0;
}