⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connect.cpp

📁 简单聊天室服务器源码
💻 CPP
字号:
// Connect.cpp : implementation file
//

#include "stdafx.h"
#include "TalkS.h"
#include "Connect.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CConnect

CConnect::CConnect(CWnd *pWnd)
{
	m_pPrev=NULL;
	m_pNext=NULL;
	m_pWnd=pWnd;
	m_bData=FALSE;
}

CConnect::~CConnect()
{
	Close();
}


// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CConnect, CAsyncSocket)
	//{{AFX_MSG_MAP(CConnect)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif	// 0

/////////////////////////////////////////////////////////////////////////////
// CConnect member functions

void CConnect::OnReceive(int nErrorCode) 
{
	// TODO: Add your specialized code here
	if(m_bData)
	{
		Receive(m_strBuf.GetBuffer(m_Msg[1]),m_Msg[1]);
		m_strBuf.ReleaseBuffer();
		if(m_Msg[0]==NET_GUEST)	m_strName=m_strBuf;

		m_pWnd->SendMessage(WM_NETDATA,m_Msg[0],(LPARAM)this);
		//由窗口响应函数调用GetBuf()或GetGuestName()
		m_bData=FALSE;
	}
	else
	{
		Receive(m_Msg,12);
		switch(m_Msg[0])
		{
		case NET_DATA:
		case NET_GUEST:	m_bData=TRUE;
			break;
		}
	}
	CAsyncSocket::OnReceive(nErrorCode);
}

void CConnect::OnClose(int nErrorCode) 
{
	// TODO: Add your specialized code here
	//要确定是否是Guest的退出,还是Sever的强制关闭
	//在WPARAM 中包含这一信息
	m_pWnd->SendMessage(WM_NETDELETE,0,(LPARAM)this);

	CAsyncSocket::OnClose(nErrorCode);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -