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.

66 lines
1.2 KiB
C++

#ifndef _CTCP_SOCKET_H
#define _CTCP_SOCKET_H
#include <afxsock.h>
//#include <vector>
//using namespace std;
#define MAX_TCP_BUF_LEN 30745
typedef void ( CALLBACK *TCPRevDataCALLBACK )( unsigned char *buffer, int length, UINT32 data);
class CTCPSocket : public CAsyncSocket
{
public:
CTCPSocket();
virtual ~CTCPSocket();
public:
bool StartListening();
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( TCPRevDataCALLBACK DataCallBack, LPVOID Param )
{
RevData = DataCallBack;
m_Param = Param;
}
bool WriteBuffer( const void *buf, unsigned int len );
protected:
virtual void OnReceive(int nErrorCode);
virtual void OnConnect(int nErrorCode);
private:
CString RemoteIP;
unsigned int RemotePort;
CString LocalIP;
unsigned int LocalPort;
TCPRevDataCALLBACK RevData;
LPVOID m_Param;
bool m_bConnected;
int m_Length;
unsigned char ReceiveBuf[MAX_TCP_BUF_LEN];
};
#endif