📄 tcpconnwrapper.h
字号:
#pragma once
namespace gaov {
namespace chaos {
#include <Winsock2.h>
#include "NetParse.h"
class TCPConn
{
public:
bool InitNetwork();
PSTREAM InitData(UINT maxlen);
int Send(PSTREAM s); // -1 : sock error; 1 : success
PSTREAM Recv(PSTREAM s, UINT length);
void Close(){
if(sock!=INVALID_SOCKET){
closesocket(sock);
sock = INVALID_SOCKET;
WSACleanup();
}
}
protected:
TCPConn() : sock(INVALID_SOCKET), m_bNetworkInited(false){}
virtual ~TCPConn(){
Close();
}
protected:
bool m_bNetworkInited;
SOCKET sock;
STREAM in;
STREAM out;
};
class TCPClient : public TCPConn
{
public:
TCPClient(){};
TCPClient(SOCKET s) { sock = s; };
~TCPClient(){}
int Connect(const char* sIP, USHORT port); // -2 : connection exists; -1 : sock error
// 0 : mem error; 1 : success
bool SendEx(UINT8 msgType, UINT8 subMsgType, PBYTE data, UINT dataLen);
bool SendEx2(UINT8 msgType, UINT8 subMsgType, PBYTE data1, UINT dataLen1, PBYTE data2, UINT dataLen2);
bool RecvEx(UINT8& msgType, UINT8& subMsgType, PBYTE& data, UINT& dataLen, const bool bRecvData=true);
bool RecvEx2(UINT8& msgType, UINT8& subMsgType, PBYTE& data1, UINT& dataLen1, PBYTE& data2, UINT& dataLen2, const bool bRecvData=true );
private:
};
class TCPServer : public TCPConn
{
public:
TCPServer(){};
~TCPServer(){}
bool Listen(const char* sIP, USHORT port);
SOCKET Accept();
private:
};
};
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -