You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.5 KiB
C

2 years ago
#ifndef _CUDP_SOCKET_H
#define _CUDP_SOCKET_H
#include <afxsock.h>
#include <vector>
using namespace std;
#define MAX_UDP_BUF_LEN 30745//25600 30745 SMData<74><61>С
//#define WM_RECEIVE_NET_DATA (WM_USER + 88)
//typedef void ( CALLBACK *UDPRevDataCALLBACK )( unsigned char *rxdata, DWORD lLen, UINT32 Param );
typedef void ( CALLBACK *UDPRevDataCALLBACK )(const void* buffer, int length, LPVOID data);
class CUDPSocket : public CAsyncSocket
{
private:
CString RemoteIP;
unsigned int RemotePort;
CString LocalIP;
unsigned int LocalPort;
unsigned char SendHDNum;
unsigned int ReceiveNum;
bool bRecSearchHead;
int m_Length;
char ReceiveBuf[MAX_UDP_BUF_LEN];
UDPRevDataCALLBACK RevData;
LPVOID m_Param;
public:
CUDPSocket();
void SetParams(CString localIP,unsigned int localPort,CString remoteIP,unsigned int remotePort);
virtual ~CUDPSocket();
bool StartListening(bool flag = false);
bool StopListening()
{
CAsyncSocket::Close();
return true;
}
void SetLocalIP( CString ip )
{
LocalIP = ip;
}
void SetLocalPort( unsigned int port )
{
LocalPort = port;
}
void SetRomoteIP( CString ip )
{
RemoteIP = ip;
}
void SetRemotePort( unsigned int port )
{
RemotePort = port;
}
void SetCallBack( UDPRevDataCALLBACK DataCallBack, LPVOID Param );
bool WriteBuffer( const void *buf, unsigned int len );
protected:
virtual void OnReceive( int nErrorCode );
};
#endif //CUdpSocket