客户端:
连接服务端
boolconnectServer(constchar*serverIP,unsignedshortport);
向服务端发送消息
voidsendMessage(char*data,255)">intcount);
接受服务端数据的回调函数
std::function<void(intcount)>onRecv;
断开连接的回调函数
void()>onDisconnect;
SocketClient.h
- #ifndef__SOCKET_CLIENT_H__
- #define__SOCKET_CLIENT_H__
- #include"SocketBase.h"
- classSocketClient:publicSocketBase
- {
- public:
- SocketClient(void);
- ~SocketClient(void);
- boolconnectServer(constchar*serverIP,unsignedshortport);
- voidsendMessage(char*data,intcount);
- std::function<void(intcount)>onRecv;
- std::function<void()>onDisconnect;
- private:
- boolinitClient();
- voidrecvMessage();
- HSocket_socketServer;
- HSocket_socektClient;
- };
- #endif
SocketClient.cpp