From 8985911d67193069a0012cba81cbaf697ad115fe Mon Sep 17 00:00:00 2001 From: TY <1431301249@qq.com> Date: Wed, 25 Jun 2025 13:13:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20TcpClient.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TcpClient.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 TcpClient.h diff --git a/TcpClient.h b/TcpClient.h new file mode 100644 index 0000000..f4fb170 --- /dev/null +++ b/TcpClient.h @@ -0,0 +1,74 @@ +#include +#include +using std::list; +#pragma once + + +typedef struct NET_TCP_PACKET2 +{ + char* pData; + int lLen; + //NET_MANAGER_ENUM enType; +}*pNET_TCP_PACKET2; + + + + +typedef unsigned int (*MsgCallBack)(PVOID); //回调函数指针 + +class CTcpClient +{ + +public: + + friend unsigned int __stdcall recvThread(LPVOID param); + + +public: + + static void UnInit(); + + BOOL ConnectServer(); + + int StopConnect(); + + int ReConnect(); + + BOOL IsConnect(){return NULL!=m_socket;} + + void RegisterHwnd(HWND hWnd, PVOID pParent); + + int SendData(char* pData, int lLen); + + void PostMessage2MainWnd(UINT uMsg, WPARAM wParam, CString strMsg); + + + int InitNetInfo(CString strConfName); + int InitNetInfo(CString strIp, int nPort); + void HandleNdcCMsg(); + char m_achSendBuf[1024]; + + ~CTcpClient(void); + + time_t m_lLastNetTime; + time_t m_lLastConnectTime; + +public: + CTcpClient(); + + SOCKET m_socket; + + CString m_strServerIp; + short m_sPort; + + HANDLE m_hReceive; + BOOL m_bStart; + +public: + PVOID m_pParent; + HWND m_hWnd; + + + +}; +