| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // testClient.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
- //
- #include "stdafx.h"
- #include <iostream>
- #include <memory>
- #include <thread>
- #include <regex>
- #include "NetInterface.h"
- #include "PduEntity.h"
- int main()
- {
- auto pClient = CNetInterface::getNetInstance();
- pClient->setLinkStateChanged([=](const PduLinkContent& linkContent) {
- auto linkState = linkContent.nLinkState;
- if (PDU_LINK_STATE_SUCCESSED == linkState) {
- std::cout << "连接成功" << std::endl;
- }
- else if (PDU_LINK_STATE_FAILED == linkState) {
- std::cout << "连接失败" << std::endl;
- }
- else if (PDU_LINK_STATE_DISCONNECTED == linkState) {
- std::cout << "连接断开" << std::endl;
- }
- else if (PDU_LINK_STATE_REG_OK == linkState) {
- std::cout << "注册成功" << std::endl;
- }
- else if (PDU_LINK_STATE_REG_FAILED == linkState) {
- std::cout << "注册失败" << std::endl;
- }
- });
- pClient->setRecvCommand([=](CPduEntity* a_pPduEntity) {
- PDU_CMD_TYPE CmdType = a_pPduEntity->GetCmdType();
- if (PDU_CMD_LISTEN == CmdType) {
- std::cout << "接收心跳" << std::endl;
- }
- else if (PDU_CMD_DEV_ONLINE_LIST == CmdType) {
- std::cout << "在线设备列表"<< a_pPduEntity->GetDataString(0).GetBuffer(0) << std::endl;
- auto devList = a_pPduEntity->GetDataString(0);
- std::string str = devList.GetBuffer(0);
- devList.ReleaseBuffer();
-
- std::smatch match;
- auto citer = str.cbegin();
- while (std::regex_search(citer, str.cend(), match, std::regex(R"(\d{1,2}\|)"))) {
- std::cout << match[0] << std::endl;
- citer = match[0].second;
- std::cout << std::endl;
- }
- }
- });
- pClient->CreatePduClient("127.0.0.1", 8811, PDU_DEV_TYPE_ACD, 1,true);
- std::this_thread::sleep_for(std::chrono::seconds(20));
- //pClient->ClosePduClient(PDU_DEV_TYPE_CTI, 1);
- //std::this_thread::sleep_for(std::chrono::seconds(20));
- std::cout << "已全部关闭" << std::endl;
- for (;;) {}
- return 0;
- }
|