serversock.cpp

来自「控制机器人完成螺丝刀插孔实验」· C++ 代码 · 共 128 行

CPP
128
字号
// ServerSock.cpp : implementation file
//

#include "stdafx.h"
#include "Server.h"
#include "ServerSock.h"
#include "ServerDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CServerSock

CServerSock::CServerSock()
{
	m_bConnected=FALSE;
}

CServerSock::~CServerSock()
{
}


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

/////////////////////////////////////////////////////////////////////////////
// CServerSock member functions

void CServerSock::OnAccept(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	CNewSocket* pSocket=new CNewSocket();
	if (Accept(*pSocket)) {
		pSocket->AsyncSelect(FD_READ);
		m_pSocket=pSocket;
		m_bConnected=TRUE;
	}
	else
		delete pSocket;
	
	CAsyncSocket::OnAccept(nErrorCode);
}
/////////////////////////////////////////////////////////////////////////////
// CServerDataSock

CServerDataSock::CServerDataSock()
{
}

CServerDataSock::~CServerDataSock()
{
}


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

/////////////////////////////////////////////////////////////////////////////
// CServerDataSock member functions

void CServerDataSock::OnAccept(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	CServerApp* pApp=(CServerApp*)AfxGetApp();
	CServerDlg* pDlg=(CServerDlg*)pApp->m_pMainWnd;
	
	CNewDataSocket* pDataSocket=new CNewDataSocket();
	if (Accept(*pDataSocket)) {
		pDataSocket->AsyncSelect(FD_READ);
		m_pDataSocket=pDataSocket;
		pDlg->m_bArray=TRUE;
	}
	else
		delete pDataSocket;
	
	CAsyncSocket::OnAccept(nErrorCode);
}
/////////////////////////////////////////////////////////////////////////////
// CServerBackDataSock

CServerBackDataSock::CServerBackDataSock()
{
}

CServerBackDataSock::~CServerBackDataSock()
{
}


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

/////////////////////////////////////////////////////////////////////////////
// CServerBackDataSock member functions

void CServerBackDataSock::OnAccept(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	CNewBackDataSocket *pBackDataSocket=new CNewBackDataSocket();
	if (Accept(*pBackDataSocket)) {
		m_backDataSocket=pBackDataSocket;
	}
	else
		delete pBackDataSocket;
	
	CAsyncSocket::OnAccept(nErrorCode);
}

⌨️ 快捷键说明

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