// // IClientSocket.h // GoldRich // // Created by WindShan on 2017/3/8. // Copyright © 2017年 WindShan. All rights reserved. // #ifndef IClientSocket_h #define IClientSocket_h #import "ClientSocket.h" #import "NetStream.h" #include using namespace std; class CClientSocket; class CNetStream; typedef void (*on_connect_success)(); typedef void (*on_connect_time_out)(); typedef void (*on_connect_error)(); typedef void (*on_receive_package)(CNetStream* pStream); class IClientSocket { public: IClientSocket(void) { pSocket = new CClientSocket(); } ~IClientSocket(void) { if (pSocket != nullptr) { delete pSocket; pSocket = nullptr; } } public: static int InitSockEnv() { return CClientSocket::InitSockEnv(); } static void UninitSockEnv() { CClientSocket::UninitSockEnv(); } int Connect(const char* ip,short port,int outTime,on_connect_success sc,on_connect_time_out tm,on_connect_error er,on_receive_package re) { if (pSocket != nullptr) { return pSocket->Connect(ip,port,outTime,sc,tm,er,re); } return -1; } int SendStream(CNetStream* pStream) { if (pSocket != nullptr) { return pSocket->SendStream(pStream); } return -1; } int Close() { if (pSocket != nullptr) { return pSocket->Close(); } return -1; } int process() //you should call this function in circle { if (pSocket != nullptr) { pSocket->process(); } return -1; } private: CClientSocket* pSocket; }; #endif /* IClientSocket_h */