添加 TcpClient.h
This commit is contained in:
		
							
								
								
									
										74
									
								
								TcpClient.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								TcpClient.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,74 @@
 | 
			
		||||
#include <winsock.h>
 | 
			
		||||
#include <list>
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user