TCP.h
上传用户:hnzycx
上传日期:2022-08-09
资源大小:12567k
文件大小:1k
- #pragma once
- #include <winsock.h>
- typedef void (CALLBACK* ONDISCONNECT) (CWnd*);
- typedef void (CALLBACK* ONREAD) (CWnd*,const char *buf, int len );
- typedef void (CALLBACK* ONERROR)(CWnd*,int nErrorCode);
- class CTCP
- {
- public:
- CTCP(void);
- ~CTCP(void);
- //服务器地址
- CString m_remoteHost;
- //服务器端口
- int m_port;
- /*以下是客户端通讯事件*/
- ONDISCONNECT OnDisConnect;
- ONREAD OnRead;
- ONERROR OnError;
- bool Open(CWnd *pWnd);
- bool Close();
- bool Connect();
- bool SendData(const char *buf, int len);
- private:
- SOCKET m_socket;
- HANDLE m_exitThreadEvent;
- HANDLE tcpThreadHandle;
- CWnd* m_pOwnerWnd;
- static DWORD SocketThreadFunc(LPVOID lparam);
- };