📄 sendclient.cpp
字号:
// SendClient.cpp : implementation file
//
#include "stdafx.h"
#include "SendClient.h"
#include "head.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSendClient
CSendClient::CSendClient(CMyWaveIn *pIn,CInterface *pInterface):
m_pIn(NULL),
m_pInterFace(NULL)
{
m_pBuffer = new char[1024];
m_pIn = pIn;
m_pInterFace = pInterface;
}
CSendClient::~CSendClient()
{
delete [1024]m_pBuffer;
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CSendClient, CAsyncSocket)
//{{AFX_MSG_MAP(CSendClient)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// CSendClient member functions
//重载OnReceive()函数
void CSendClient::OnReceive(int nErrorCode)
{
struct TalkFrame *frame;
frame = (struct TalkFrame *)m_pBuffer;
int iLen = sizeof(struct TalkFrame);
//接收缓存中所有的TalkFrame结构
while(iLen > 0)
{
//接收数据
int i = Receive (
m_pBuffer + sizeof(struct TalkFrame) - iLen,iLen);
//出错
if (i == SOCKET_ERROR )
//返回
return ;
iLen -= i;
}
//如果不是正常数据就返回
if (strcmp(frame->cFlag ,"TalkFrame") != 0)
{
return;
}
iLen = frame->iLen;
//接收缓存中所有的音频数据
while (iLen > 0)
{
//接收数据
int i = Receive (m_pBuffer + sizeof(struct TalkFrame)
+ (frame->iLen - iLen),iLen);
//出错
if (i == SOCKET_ERROR)
//返回
return ;
iLen -= i;
}
//对方地址
CString add;
//端口
UINT port;
switch (frame->iCom )
{
//正常通信帧
case TC_AGREE_TALK:
//获取连接对方地址和端口
GetPeerName (add,port);
//提示开始工作
m_pInterFace->TalkStart (add);
//允许发送数据
m_pIn->EnableSend (TRUE);
//设置允许工作标志
m_pInterFace->m_bWork = TRUE;
break;
default:
break;
}
//调用基类OnReceive()函数
CAsyncSocket::OnReceive(nErrorCode);
}
void CSendClient::OnClose(int nErrorCode)
{
//设置连接断开标志
m_bConnect = FALSE;
//关闭
m_pInterFace->BeClose ();
//调用基类OnClose()函数
CAsyncSocket::OnClose(nErrorCode);
}
void CSendClient::OnConnect(int nErrorCode)
{
//获取连接结果
m_pInterFace->ConnectResult(nErrorCode);
//调用基类OnConnect()函数
CAsyncSocket::OnConnect(nErrorCode);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -