提交说明

This commit is contained in:
李广豪 2025-06-16 13:31:11 +08:00
parent 88acb23465
commit 7e13599f5c
10 changed files with 131 additions and 23 deletions

View File

@ -22,7 +22,7 @@
<ProjectGuid>{548705F2-AF3E-45B7-A716-578791B1ECBE}</ProjectGuid>
<RootNamespace>CCEXPipe</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
@ -35,7 +35,7 @@
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
@ -45,7 +45,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">

View File

@ -21,7 +21,7 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{4DA0C82B-2496-4A33-BDCE-E89D85A60BF8}</ProjectGuid>
<RootNamespace>VcsClient</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
<Keyword>MFCProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@ -43,14 +43,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>

View File

@ -21,7 +21,7 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{8BBB60C1-510D-47BC-8FD2-E14E9EA3A156}</ProjectGuid>
<RootNamespace>VcsClient</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
<Keyword>MFCProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@ -43,14 +43,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>

View File

@ -133,7 +133,6 @@ CString CFastApp::SendMsg2Platform(CString strReceiver, int nMsgType, Json::Valu
string strJson = writer.write(root);
g_pstPipeClient->SendeMsg(WCS_2_WMS_DATA, (char*)strJson.c_str(), strJson.length());
LogOutToFile("FAST::SendMsg2Platform End");
return "";

View File

@ -23,7 +23,7 @@
<ProjectGuid>{EDB92B51-C3C2-44DA-B21D-6BB824264D08}</ProjectGuid>
<RootNamespace>GrabImage_Display</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
@ -40,14 +40,14 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>

View File

@ -121,7 +121,107 @@ void CFastMainDialog::ProcessPipeMsg(int lMsgId, char* pData, int lLen)
LogOutToFile("HttpServiceListener::OnRecvRequest End");
}
// TCP服务端线程
UINT CFastMainDialog::TCPListenerThread(LPVOID pParam) {
CFastMainDialog* pThis = (CFastMainDialog*)pParam;
SOCKET hServer = pThis->m_hServerSocket;
while (true) {
SOCKET hClient = accept(hServer, NULL, NULL);
if (hClient == INVALID_SOCKET) continue;
char buffer[4096];
int bytesRecv = recv(hClient, buffer, sizeof(buffer), 0);
if (bytesRecv > 0) {
CString strMsg(buffer, bytesRecv);
pThis->ProcessTCPMessage(strMsg);
}
closesocket(hClient);
}
return 0;
}
// 处理收到的TCP消息
void CFastMainDialog::ProcessTCPMessage(const CString& strJson) {
LogOutToFile("FAST::ProcessTCPMessage Received: %s", strJson);
Json::Reader reader;
Json::Value root;
if (!reader.parse((LPCTSTR)strJson, root)) {
LogOutToFile("JSON parse error!");
return;
}
// 验证必要字段
if (!root.isMember("receiver") || !root.isMember("type")) {
LogOutToFile("Invalid message format");
return;
}
// 通过现有平台接口转发
CString strReceiver = root["receiver"].asString().c_str();
int nMsgType = root["type"].asInt();
Json::Value params = root.get("params", Json::nullValue);
theApp.SendMsg2Platform(strReceiver, nMsgType, params);
}
// 启动TCP服务
void CFastMainDialog::StartTCPServer()
{
// 1. 初始化Winsock
WSADATA wsaData;
int wsResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (wsResult != 0) {
LogOutToFile("[TCP] WSAStartup failed: %d", wsResult);
return;
}
// 2. 创建Socket
m_hServerSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (m_hServerSocket == INVALID_SOCKET) {
LogOutToFile("[TCP] Socket creation failed: %d", WSAGetLastError());
WSACleanup();
return;
}
// 3. 设置端口复用(可选)
int optval = 1;
setsockopt(m_hServerSocket, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof(optval));
// 4. 绑定端口
sockaddr_in service;
service.sin_family = AF_INET;
service.sin_addr.s_addr = INADDR_ANY;
service.sin_port = htons(6000);
if (::bind(m_hServerSocket, (SOCKADDR*)&service, sizeof(service)) == SOCKET_ERROR)
{
LogOutToFile("[TCP] Bind failed on port 6000: %d", WSAGetLastError());
closesocket(m_hServerSocket);
WSACleanup();
return;
}
// 5. 开始监听
if (listen(m_hServerSocket, SOMAXCONN) == SOCKET_ERROR)
{
LogOutToFile("[TCP] Listen failed: %d", WSAGetLastError());
closesocket(m_hServerSocket);
WSACleanup();
return;
}
// 6. 启动线程
m_pListenerThread = AfxBeginThread(TCPListenerThread, this);
if (m_pListenerThread == NULL) {
LogOutToFile("[TCP] Thread creation failed!");
closesocket(m_hServerSocket);
WSACleanup();
return;
}
LogOutToFile("[TCP] Server successfully started on port 6000");
}
BOOL CFastMainDialog::OnInitDialog()
{
CDialogEx::OnInitDialog();
@ -155,7 +255,7 @@ BOOL CFastMainDialog::OnInitDialog()
//初始化本地相机
InitLocalCamera();
StartTCPServer(); // 新增TCP服务启动
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}

View File

@ -13,6 +13,9 @@ public:
CFastMainDialog(CWnd* pParent = NULL); // 标准构造函数
virtual ~CFastMainDialog();
void StartTCPServer();
void StopTCPServer();
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_MAIN_DIALOG };
@ -35,4 +38,10 @@ public:
afx_msg void OnTimer(UINT_PTR nIDEvent);
void ProcessPipeMsg(int lMsgId, char* pData, int lLen);
private:
static UINT __cdecl TCPListenerThread(LPVOID pParam);
void ProcessTCPMessage(const CString& strJson);
CWinThread* m_pListenerThread;
SOCKET m_hServerSocket;
};

View File

@ -21,7 +21,7 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{77089A10-F10B-4E0E-B045-86271BFD1A07}</ProjectGuid>
<RootNamespace>VcsClient</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
<Keyword>MFCProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@ -43,14 +43,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>

View File

@ -21,7 +21,7 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{CD291D2B-F677-46FC-BC5F-0C4A18CBBC11}</ProjectGuid>
<RootNamespace>VcsClient</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
<Keyword>MFCProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@ -43,14 +43,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>

View File

@ -23,7 +23,7 @@
<ProjectGuid>{A98ADD5C-021A-494A-9E04-61E7F3220104}</ProjectGuid>
<RootNamespace>GrabImage_Display</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
@ -40,14 +40,14 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>