@@ -42,11 +42,13 @@ int HHRegisterService(const char* deviceName)
42
42
"deviceType": "SmartSpeaker"
43
43
})" ;
44
44
45
-
46
- // mdnsClient->RegisterService("MyDeviceService", "_wsraop._tcp", 7890, jsonString1);
47
- // mdnsClient->RegisterService("MyDeviceService2", "_smart._tcp", 8899, jsonString2);
48
-
49
- // mdnsClient->RegisterService("MyDeviceService_Android7767", "_wsraop._tcp", 7767, jsonString1);
45
+ // for test
46
+ mdnsClient->RegisterService (" Service1" , " _hhclient._tcp" , 1111 , jsonString1);
47
+ mdnsClient->RegisterService (" Service2" , " _hhclient._tcp" , 2222 , jsonString2);
48
+ mdnsClient->RegisterService (" Service3" , " _hhclient._tcp" , 3333 , jsonString1);
49
+ mdnsClient->RegisterService (" Service4" , " _hhclient._tcp" , 4444 , jsonString2);
50
+ mdnsClient->RegisterService (" Service5" , " _hhclient._tcp" , 5555 , jsonString1);
51
+ mdnsClient->RegisterService (" Service6" , " _hhclient._tcp" , 6666 , jsonString2);
50
52
51
53
mdnsClient->StartBrowseService (" _hhclient._tcp" , [](const std::string& jsonTxtRecord) {
52
54
std::cout << " Discovered JSON TXT Record: " << jsonTxtRecord << std::endl;
@@ -55,65 +57,7 @@ int HHRegisterService(const char* deviceName)
55
57
56
58
std::this_thread::sleep_for (std::chrono::milliseconds (5000 ));
57
59
58
- // mdnsClient->StopBrowseService("_hhclient._tcp");
60
+ mdnsClient->StopBrowseService (" _hhclient._tcp" );
59
61
60
- // mdnsClient->StartBrowseService("_smart._tcp", [](const std::string& jsonTxtRecord) {
61
- // std::cout << "Discovered JSON TXT Record: " << jsonTxtRecord << std::endl;
62
- // });
63
62
return 0 ;
64
- }
65
-
66
- #if 0
67
- int main()
68
- {
69
- // JSON 字符串
70
- std::string jsonString1 = R"({
71
- "name": "Device1",
72
- "width": "1920",
73
- "height": "1080",
74
- "deviceType": "SmartTV"
75
- })";
76
-
77
- std::string jsonString2 = R"({
78
- "name": "Device2",
79
- "width": "1280",
80
- "height": "720",
81
- "deviceType": "SmartSpeaker"
82
- })";
83
-
84
-
85
- std::shared_ptr<MDNSClient> mdnsClient = std::make_shared<MDNSClient>();
86
- mdnsClient->RegisterService("MyDeviceService1", "_wsraop._tcp", 7788, jsonString1);
87
- mdnsClient->RegisterService("MyDeviceService2", "_smart._tcp", 8899, jsonString2);
88
-
89
-
90
- mdnsClient->StartBrowseService("_wsraop._tcp", [](const std::string& jsonTxtRecord) {
91
- std::cout << "Discovered JSON TXT Record: " << jsonTxtRecord << std::endl;
92
- });
93
- mdnsClient->StartBrowseService("_smart._tcp", [](const std::string& jsonTxtRecord) {
94
- std::cout << "Discovered JSON TXT Record: " << jsonTxtRecord << std::endl;
95
- });
96
-
97
- // 阻塞主线程,直到输入 'q' 字符
98
- char input;
99
- std::cout << "Enter 'q' to quit the application." << std::endl;
100
- std::cout << "Enter 'u' to unregister service." << std::endl;
101
- while (std::cin >> input) {
102
- if (input == 'q') {
103
- break;
104
- }
105
- else if (input == 'u') {
106
- mdnsClient->UnregisterService("MyDeviceService1", "_wsraop._tcp");
107
- }
108
- else if (input == 's') {
109
- mdnsClient->StopBrowseService("_wsraop._tcp");
110
- }
111
- std::cout << "Invalid input. Enter 'q' to quit the application." << std::endl;
112
- }
113
-
114
-
115
-
116
-
117
- return 0;
118
- }
119
- #endif
63
+ }
0 commit comments