www.gusucode.com > 用ActiveX重新包装了一个点对点通讯的DLL文件源码程序 > 用ActiveX重新包装了一个点对点通讯的DLL文件源码程序/P2P语音通信/ClientSocket.cpp
/***************************************************** 作者:你家的玻璃不是我砸的@vckbase.com 联系方法:xiny120@hotmail.com BLOG:http://blog.vckbase.com/zaboli http://www.hotlove.cn 程序简介: 用ActiveX重新包装了一个点对点通讯的DLL文件(该DLL文件是VCKBASE上的一位前辈写的) 偶只是把它改成了一个MFC的ActiveX,这样可以方便的在VB,vbs,js等脚本语言,特别是用在IE 里面特别方便了。 此程序主要向你说明,其实ActiveX没有多么的神秘。你遵守的它的规则,什么功能都能添加到 ActiveX中,并且和写其它的普通的程序没有什么区别! 缺点:因为同时只能有一个程序打开音频设备,所以不能开两个实例进行聊天。本来打算改改好,只 发布成品ActiveX,不发布原代码的。可最近鸟事很多,没时间。。所以连源代码都贡献了~~~ 大家可以自己完善一下。如果您做了什么好的改进,请您给作者我发一份,我会十分感谢!!! ********************************************************/ // ClientSocket.cpp : implementation file // #include "stdafx.h" #include "ClientSocket.h" #include "head.h" #include "RecSocket.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CClientSocket CClientSocket::CClientSocket(CInterface *pInterFace,CMyWaveIn *pIn,CUdpSocket *pUdp): m_bConnect(FALSE), m_pInterface (NULL), m_pIn(NULL), m_pUdp (NULL) { m_pBuffer = new char[1024]; m_pInterface = pInterFace; m_pIn = pIn; m_pUdp = pUdp; } CClientSocket::~CClientSocket() { delete []m_pBuffer; } // Do not edit the following lines, which are needed by ClassWizard. #if 0 BEGIN_MESSAGE_MAP(CClientSocket, CSocket) //{{AFX_MSG_MAP(CClientSocket) //}}AFX_MSG_MAP END_MESSAGE_MAP() #endif // 0 ///////////////////////////////////////////////////////////////////////////// // CClientSocket member functions void CClientSocket::OnClose(int nErrorCode) { // TODO: Add your specialized code here and/or call the base class m_bConnect = FALSE; m_pInterface->BeClose (); CSocket::OnClose(nErrorCode); } void CClientSocket::OnReceive(int nErrorCode) { // TODO: Add your specialized code here and/or call the base class struct TalkFrame *frame; frame = (struct TalkFrame *)m_pBuffer; int iLen = sizeof(struct 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; 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_NORMAL_TALK: memset(frame,0,sizeof (struct TalkFrame)); sprintf(frame->cFlag,"TalkFrame"); GetPeerName (add,port); if (m_pInterface ->IsConnect (add)) { frame->iCom = TC_AGREE_TALK; frame->iLen = 0; if (SOCKET_ERROR == Send (m_pBuffer,sizeof(struct TalkFrame))) { TRACE("Send agree command fail.\n"); break ; }; m_pInterface->TalkStart (add); m_pUdp->SetIp (add,(m_pInterface->GetRecSocket())->GetListenPort()); m_pIn->EnableSend (TRUE); m_pInterface->m_bWork = TRUE; break; }; frame->iCom = TC_DISAGREE_TALK; frame->iLen = 0; Send (m_pBuffer,sizeof(struct TalkFrame)); Close (); break; default: break; } CSocket::OnReceive(nErrorCode); }