www.gusucode.com > UDP语音通讯控件源码程序 > UDP语音通讯控件源码程序/AUDIOS/AUDIO/UdpSocket.cpp
// UdpSocket.cpp : implementation file // #include "stdafx.h" #include "UdpSocket.h" #include "head.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CUdpSocket CUdpSocket::CUdpSocket() { m_recvpFrame = (struct Frame *)m_RBuffer; m_pFrame = (struct Frame *)m_cBuffer; m_pFrame->iIndex = 0; m_recvpFrame->iIndex = 0; m_bIni = FALSE; } CUdpSocket::~CUdpSocket() { } // Do not edit the following lines, which are needed by ClassWizard. #if 0 BEGIN_MESSAGE_MAP(CUdpSocket, CAsyncSocket) //{{AFX_MSG_MAP(CUdpSocket) //}}AFX_MSG_MAP END_MESSAGE_MAP() #endif // 0 ///////////////////////////////////////////////////////////////////////////// // CUdpSocket member functions BOOL CUdpSocket::Ini(UINT nPort) { if (m_bIni) return FALSE; if (!Create(nPort,SOCK_DGRAM)) return FALSE; m_bIni = TRUE; return TRUE; } int CUdpSocket::Send(const void* lpBuf, int nBufLen, int nFlags) { // TODO: Add your specialized code here and/or call the base class m_pFrame->iIndex ++; memcpy(m_cBuffer + sizeof(struct Frame),lpBuf,nBufLen); return CAsyncSocket::SendTo(m_pFrame, nBufLen + sizeof(struct Frame),m_nPort,m_ip, nFlags); } void CUdpSocket::OnReceive(int nErrorCode) { // TODO: Add your specialized code here and/or call the base class m_iLen = sizeof(m_RBuffer); m_iLen = this->ReceiveFrom(m_recvpFrame,m_iLen,m_ip,m_nPort); if (m_iLen !=0) { m_sort.ReceiveData ((char *)m_recvpFrame,m_iLen); } CAsyncSocket::OnReceive(nErrorCode); } BOOL CUdpSocket::CloseSocket() { if (!m_bIni) return FALSE; m_bIni = FALSE; CAsyncSocket::Close (); return TRUE; } void CUdpSocket::SetIp(CString ip) { m_ip = ip; } void CUdpSocket::SetPort(UINT nPort) { m_nPort=nPort; }