www.pudn.com > IP_phone.rar > RecSocket.cpp


/**********************************************************/ 
/*类名:CRecSocket                                        */ 
/*简述:用于接受的UDPSocket                               */ 
/**********************************************************/ 
// RecSocket.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "..\NC_Client.h" 
#include "RecSocket.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CRecSocket 
 
CRecSocket::CRecSocket(CNC_ClientDlg *temp) 
{ 
	m_sort=new CSortData(temp); 
	m_bIni = FALSE; 
	m_pFrame = (struct Frame *)m_cBuffer; 
} 
 
CRecSocket::~CRecSocket() 
{ 
} 
 
// Do not edit the following lines, which are needed by ClassWizard. 
#if 0 
BEGIN_MESSAGE_MAP(CRecSocket, CAsyncSocket) 
	//{{AFX_MSG_MAP(CRecSocket) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
#endif	// 0 
 
///////////////////////////////////////////////////////////////////////////// 
// CRecSocket member functions 
//初始化 
BOOL CRecSocket::Ini() 
{ 
	if (m_bIni) 
		return FALSE; 
 
	//设定接受端口和UDP 
	if (!Create (1003,SOCK_DGRAM)) 
		return FALSE; 
 
	m_bIni = TRUE; 
	return TRUE; 
} 
///////////////////////////////////////////////////////////////////////////// 
//重载onreceive() 
void CRecSocket::OnReceive(int nErrorCode)  
{ 
	m_iLen=sizeof(m_cBuffer); 
	m_iLen=this->Receive(m_cBuffer,m_iLen); 
	m_sort->Play(m_cBuffer,m_iLen); 
 
	CAsyncSocket::OnReceive(nErrorCode); 
} 
///////////////////////////////////////////////////////////////////////////// 
//release 
BOOL CRecSocket::CloseSocket() 
{ 
	if (!m_bIni) 
		return FALSE; 
	m_bIni = FALSE; 
	CAsyncSocket::Close (); 
	return TRUE; 
} 
/////////////////////////////////////////////////////////////////////////////