TCP服务端修改

This commit is contained in:
2025-06-18 18:17:05 +08:00
parent 6e24151113
commit c0a5ddfeb7

View File

@@ -122,7 +122,7 @@ void CFastMainDialog::ProcessPipeMsg(int lMsgId, char* pData, int lLen)
}
// TCP<43><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
UINT CFastMainDialog::TCPListenerThread(LPVOID pParam) {
/*UINT CFastMainDialog::TCPListenerThread(LPVOID pParam) {
CFastMainDialog* pThis = (CFastMainDialog*)pParam;
SOCKET hServer = pThis->m_hServerSocket;
@@ -139,6 +139,34 @@ UINT CFastMainDialog::TCPListenerThread(LPVOID pParam) {
closesocket(hClient);
}
return 0;
}*/
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;
// <20><><EFBFBD><EFBFBD>Nagle<6C><EFBFBD><E3B7A8><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
int optval = 1;
setsockopt(hClient, IPPROTO_TCP, TCP_NODELAY, (char*)&optval, sizeof(optval));
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>ӹر<D3B9>
char buffer[4096];
while (true) {
int bytesRecv = recv(hClient, buffer, sizeof(buffer), 0);
if (bytesRecv <= 0) { // <20><><EFBFBD>ӶϿ<D3B6><CFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LogOutToFile("[TCP] Client disconnected or error: %d", WSAGetLastError());
break;
}
CString strMsg(buffer, bytesRecv);
pThis->ProcessTCPMessage(strMsg);
}
closesocket(hClient); // <20><><EFBFBD>չر<D5B9><D8B1><EFBFBD><EFBFBD><EFBFBD>
}
return 0;
}
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>TCP<43><50>Ϣ