-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotify-Example.cpp
More file actions
73 lines (58 loc) · 1.81 KB
/
Notify-Example.cpp
File metadata and controls
73 lines (58 loc) · 1.81 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
72
73
#include <thread>
#include <iostream>
#include <chrono>
#include "SocketLib/SocketLib.h"
#if defined (_WIN32) || defined (_WIN64)
#include <conio.h>
#else // Linux
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
auto _kbhit = []() -> int
{
struct termios oldt, newt;
int ch;
int oldf;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if (ch != EOF)
{
ungetc(ch, stdin);
return 1;
}
return 0;
};
#define localtime_s(x,y) localtime_r(y,x)
#endif
int main(int argc, const char* argv[])
{
#if defined(_WIN32) || defined(_WIN64)
// Detect Memory Leaks
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
#endif
BaseSocket::EnumIpAddresses([](int iAddrType, const std::string& strAddr, int iPort, void*) -> int
{
std::cout << "IP Address: " << strAddr << ", Port: " << iPort << ", Type: " << iAddrType << std::endl;
return 0; // continue enumeration
}, nullptr);
BaseSocket::SetAddrNotifyCallback([](bool bAdded, const std::string& strAddr, int iPort, int iAddrType)
{
std::cout << "Address " << (bAdded ? "added" : "removed") << ": " << strAddr << ", Port: " << iPort << ", Type: " << iAddrType << std::endl;
});
const char caZeichen[] = "\\|/-";
int iIndex{0};
while (_kbhit() == 0)
{
std::cout << '\r' << caZeichen[iIndex++] << std::flush;
if (iIndex > 3) iIndex = 0;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
return 0;
}