123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #ifndef __TCP_CLIENT_HEADER__
- #define __TCP_CLIENT_HEADER__
- #include "Global.h"
- // winsocket库;
- #include <Ws2tcpip.h>
- #pragma comment(lib,"Ws2_32.lib")
- #pragma once
- #ifdef IRCONTROL_EXPORTS
- #define IRCONTROL_API __declspec(dllexport)
- #else
- #define IRCONTROL_API __declspec(dllimport)
- #endif
- class IRCONTROL_API CTCPClient
- {
- public:
- CTCPClient();
- ~CTCPClient();
- // 初始化套接字库;
- bool InitSocket();
- // 连接服务器;
- bool Connect(std::string ip, int port);
- // 连接服务器;
- bool SelectConnect(std::string ip, int port, int time_out = 3);
- // 断开连接;
- void DisConnect();
- // 发送数据;
- bool Send(std::string s_data, std::string &r_data);
- // 重连;
- void ReConnect(DWORD dwError = WSAENETRESET);
- protected:
- bool checkEOM(std::string& data);
- private:
- // 客户端套接字;
- SOCKET m_socket;
- // 客户端地址;
- sockaddr_in m_sin;
- // ip;
- std::string m_ip;
- // port;
- int m_port;
- };
- #endif //__TCP_CLIENT_HEADER__
|