#pragma once
|
#include <vector>
|
#include <memory>
|
#include "MyCircularBuf.h"
|
// CMyAsyncSocket1 ÃüÁîÄ¿±ê
|
double GetTimeMs();
|
|
class CMyDataSocket;
|
class CMyServerSocket : public CAsyncSocket
|
{
|
public:
|
CMyServerSocket();
|
virtual ~CMyServerSocket();
|
int Idx;
|
int SN;
|
virtual void OnAccept(int nErrorCode);
|
virtual void OnClose(int nErrorCode);
|
virtual void OnConnect(int nErrorCode);
|
std::vector<std::shared_ptr<CMyDataSocket>> MySockets;
|
int UpdataStat();
|
|
};
|
struct stVerInfo
|
{
|
short nMainVer;
|
short nSubVer;
|
};
|
struct ClientInfo
|
{
|
stVerInfo ClientVer;
|
int nType;
|
CString TypeStr;
|
int nGroup;
|
CString GroupStr;
|
int Online;
|
CTime OnTime;
|
CTime OffTime;
|
};
|
class CMyDataSocket : public CAsyncSocket
|
{
|
public:
|
enum enConnectionStat
|
{
|
statIdel=0,
|
statListening=1,
|
statToConnect=2,
|
statConnected=3,
|
statMeToClose=4,
|
statBeToClose=5,
|
statClosed=6,
|
statTimeWait=7,
|
statToDel=8,
|
};
|
enum enCMDs
|
{
|
cmdNone=0,
|
cmdPing=1,
|
cmdPingReply=2,
|
cmdHeartBeat=3,
|
cmdMessage=4,
|
cmdGetVersion=5,
|
cmdVerInfo=6,
|
|
cmdNeedLogin=10,
|
cmdLogin=11,
|
cmdLogout=12,
|
cmdAcceptLogin=13,
|
cmdDenyLogin=14,
|
cmdPutName=15,
|
|
cmdSendDummyData=20,
|
|
cmdSendFile=30,
|
cmdAcceptFile=31,
|
cmdPutFile=32,
|
cmdGetFile=33,
|
cmdSendFileData=35,
|
|
cmdListDir=40,
|
cmdDirData=41,
|
cmdGetStat=42,
|
cmdSentStat=43,
|
|
};
|
enum enDataType
|
{
|
dataNone=0,
|
dataFileInfo=1,
|
dataFileData=2,
|
dataTypeVerInfo=5,
|
dataTypeUserPass=10,
|
|
};
|
struct stFileInfo
|
{
|
CTime m_cTime;
|
CTime m_mTime;
|
CTime m_aTime;
|
INT64 nFileSize;
|
DWORD nFileAttr;
|
};
|
#pragma warning(disable : 4200)
|
typedef struct tagFileInfo
|
{
|
CTime m_cTime;
|
CTime m_mTime;
|
CTime m_aTime;
|
INT64 nFileSize;
|
DWORD nFileAttr;
|
DWORD nFileNameLength;
|
char m_FileName[];
|
}*pFileInfo;
|
|
typedef struct tagPacket
|
{
|
short sign; //°üÍ·±ê¼Ç
|
short nChannel; //ͨµÀ
|
short nCMD; //ÃüÁî
|
short Param1; //²ÎÊý1
|
short param2; //²ÎÊý2
|
short param3; //²ÎÊý3
|
short nDataType; //Êý¾ÝÀàÐÍ
|
USHORT nDataSize; //Êý¾Ý´óС
|
char data[0]; //Êý¾ÝÔغÉ
|
}* pPacket;
|
public:
|
CMyDataSocket();
|
virtual ~CMyDataSocket();
|
virtual void OnAccept(int nErrorCode);
|
virtual void OnClose(int nErrorCode);
|
virtual void OnConnect(int nErrorCode);
|
virtual void OnOutOfBandData(int nErrorCode);
|
virtual void OnReceive(int nErrorCode);
|
virtual void OnSend(int nErrorCode);
|
int TriggerSend();
|
int MakeCtrlPacket(pPacket p2, int Type, int nParam1);
|
int MakeDataPacket(pPacket p2, int Type, int nParam1, int Datatype, int nDataLen, void * DataBuf);
|
|
int SendPacket(pPacket p2, int length);
|
int StartSendMass(int Length, int Count);
|
int SendFile(CString sFilePathName);
|
int ContinueReadFile(char * pFileBuf, int nBlockSize);
|
int ProcessPacket(pPacket p1);
|
int DoRecvFile(pFileInfo pf1);
|
int DoPing();
|
int SocketType;
|
int Idx;
|
int SN;
|
int ConnectionStat; //״̬
|
// CString sipaddrto;
|
// int portto;
|
// INT64 BytesToSend;
|
// DWORD dwError;
|
CTime m_cTime; //Á¬½Óʱ¿Ì;
|
CTime m_kTime; //¶Ï¿ªÊ±¿Ì;
|
|
stVerInfo TargetVer; //¶Ô·½°æ±¾;
|
CString sTargetIp; //¶Ô·½IP£»
|
UINT nTargetPort; //¶Ô·½¶Ë¿Ú
|
int Logined; //ÊÇ·ñµÇ¼;
|
|
|
int nPingInterval; //ping¼ä¸ô,0±íʾûÓÐ
|
int nIntervalCount; //¼ä¸ô¼ÆÊý
|
int bPinging; //ÊÇ·ñÕýÔÚping
|
int PingSeq; //pingÐòºÅ
|
double pingTime; //ping·¢³öʱ¼ä;
|
double latancy; //ÑÓ³Ù;
|
|
int bToSendFile;
|
int bSendingFile;
|
int bRecvingFile;
|
INT64 DummyToSend;
|
CFileException e1;
|
CFile m_filesend1;
|
CFile m_filerecv1;
|
INT64 nSendFileSize;
|
INT64 nFileSentSize;
|
INT64 nRecvFileSize;
|
INT64 nFileRecvedSize;
|
stFileInfo mRecvFileInfo;
|
static const int tempsendbufsize=65536;
|
static const int nMaxFileBlockSize=60000;
|
static const int nMaxDummyBlockSize=60000;
|
static const int SendBufSize=2560000;
|
static const int RecvBufSize=2560000;
|
CMyCircularBuf SendBuf;
|
CMyCircularBuf RecvBuf;
|
char tempSendbuf1[tempsendbufsize];
|
char tempRecvbuf1[65536];
|
volatile INT64 TotalSendBytes,TotalRecvBytes;
|
volatile DWORD SendBytes,RecvBytes;
|
volatile DWORD LastSendBytes,LastRecvBytes;
|
volatile DWORD SendSpeed,RecvSpeed;
|
int UpdateSpeed();
|
};
|
|
|
|
class CMyPingSocket : public CAsyncSocket
|
{
|
public:
|
CMyPingSocket();
|
~CMyPingSocket();
|
typedef struct IpHeader{//IP±¨Í·¸ñʽ
|
unsigned char hdr_len:4;//4λͷ²¿³¤¶È
|
unsigned char version:4;//4λ°æ±¾ºÅ
|
unsigned char tos;//8λ·þÎñÀàÐÍ
|
unsigned short total_len;//16λ×ܳ¤¶È
|
unsigned short identifier;//16λ±êʾ·û
|
unsigned short frag_and_flags;//3λ±êÖ¾¼Ó13λƬƫÒÆ
|
unsigned char tt1;//8λÉú´æʱ¼ä
|
unsigned char protocol;//8λÉϲãÐÒéºÅ
|
unsigned short checksum;//16λУÑéºÍ
|
unsigned long sourceIP;//32λԴIPµØÖ·
|
unsigned long destIP;//32λĿµÄIPµØÖ·
|
}* pIpHeader;
|
typedef struct IcmpHeader{//ICMPµÄ±¨Í·¸ñʽ
|
BYTE i_type;//ICMPÀàÐÍÂë
|
BYTE i_code;//×ÓÀàÐÍÂë
|
USHORT i_cksum;//УÑéºÍ
|
USHORT i_id;//ICMPÊý¾Ý±¨µÄIDºÅ
|
USHORT i_seq;//ICMPÊý¾Ý±¨µÄÐòÁкÅ
|
// ULONG timestamp;//¿ÉÑ¡Êý¾Ý²¿·Ö£¬¿ÉÒÔºöÂÔ
|
char datas[];
|
}* pIcmpHeader;
|
|
int Init();
|
virtual void OnReceive(int nErrorCode);
|
char RecvBuf1[65536];
|
char SendBuf1[65536];
|
int seq;
|
struct stPingStruct
|
{
|
CString sHostName;
|
double PingTime;
|
short seq;
|
bool Pinging;
|
bool Replied;
|
}Hosts[100];
|
int TotalHosts;
|
static USHORT checksum(USHORT * pBuf,int iSize);
|
static void fill_icmp_data(char *pBuf,int iSize);
|
int DoPings();
|
int AddHostToList(CString HostAddr);
|
int DelHostFromList(int index);
|
int EmptyList();
|
};
|
|
class CMyUDPSocket1 : public CAsyncSocket
|
{
|
virtual void OnReceive(int nErrorCode);
|
//virtual void OnSend(int nErrorCode);
|
|
};
|
|
class CMyUDPSocket2 : public CAsyncSocket
|
{
|
virtual void OnReceive(int nErrorCode);
|
//virtual void OnSend(int nErrorCode);
|
|
};
|
|
class CMyUDPSocket3 : public CAsyncSocket
|
{
|
virtual void OnReceive(int nErrorCode);
|
//virtual void OnSend(int nErrorCode);
|
|
};
|