www.pudn.com > 密聊源程序.rar > ListenSocket.cpp


// ListenSocket.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "SecretChat.h"		//应用程序类头文件 
#include "ListenSocket.h" 
#include "ServiceSocket.h" 
#include "SecretChatDlg.h"	//主窗口类头文件 
 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CListenSocket 
 
CListenSocket::CListenSocket() 
{ 
} 
 
CListenSocket::~CListenSocket() 
{ 
} 
 
 
// Do not edit the following lines, which are needed by ClassWizard. 
#if 0 
BEGIN_MESSAGE_MAP(CListenSocket, CSocket) 
	//{{AFX_MSG_MAP(CListenSocket) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
#endif	// 0 
 
///////////////////////////////////////////////////////////////////////////// 
// CListenSocket member functions 
 
void CListenSocket::OnAccept(int nErrorCode)  
{ 
	CSecretChatDlg * pMain = (CSecretChatDlg *)AfxGetMainWnd(); 
 
	if(pMain->m_online) 
	{ 
		//已经联机就不在联机了 
		pMain->m_statusMessages.SetWindowText("有人尝试连接"); 
		::MessageBeep(MB_OK); 
		return; 
	} 
 
	if( NULL != (m_pServiceSocket = new CServiceSocket)//构造套接字 
		&& Accept(*m_pServiceSocket) ) 
	{ 
		pMain->m_clientOrService = TRUE;	//服务器端 
		pMain->connect_succeed_update(); 
	} 
	else 
	{ 
		pMain->m_statusMessages.SetWindowText("连接失败!"); 
		//关闭套接字 
		pMain->CloseSocket(); 
	} 
 
}