admin
2022-08-25 14db1514fec89db599766d4996b4bb1fead0eff0
app/SocketManager.cpp
@@ -4,6 +4,7 @@
#include <thread>
#include <string>
SOCKET SocketManager::socketServer;
ActionCallback SocketManager::actionCallback;
@@ -14,7 +15,7 @@
SocketManager::SocketManager(ActionCallback callback, void* context) {
   init(callback,context);
   init(callback, context);
}
SocketManager::~SocketManager() {
@@ -31,26 +32,13 @@
      if (recv_len > 0)
      {
         cout << "接受到操作指令:" << recvBuff << endl;
         try {
            bool success = actionCallback(string(recvBuff), callbackContext);
            //发送操作结果
            if (success)
            {
               char buff[] = "OK";
               int iSend = send(client, buff, sizeof(buff), 0);
               cout << "返回给客户端数据:" << buff << endl;
            }
            else {
               char buff[] = "FAIL";
               int iSend = send(client, buff, sizeof(buff), 0);
               cout << "返回给客户端数据:" << buff << endl;
            }
         }
         catch (string st) {
            char buff[] = "FAIL";
            int iSend = send(client, buff, sizeof(buff), 0);
            cout << "设置采集代码出错:" << st << endl;
         }
         string result = actionCallback(string(recvBuff), callbackContext);
         //发送操作结果
         int iSend = send(client, result.c_str(), result.size(), 0);
         cout << "返回给客户端数据:" << result << endl;
      }
      else {
         cout << "客户端退出" << endl;