serversocket.cpp

来自「CMPP3.0模拟网关」· C++ 代码 · 共 96 行

CPP
96
字号
// ServerSocket.cpp : implementation file
//

#include "stdafx.h"
#include "CmppGateway.h"
#include "ServerSocket.h"
#include "ManagerSocket.h"

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

/////////////////////////////////////////////////////////////////////////////
// CServerSocket

CServerSocket::CServerSocket(CManagerSocket *pManagerSocket)
{
	m_pManagerSocket = pManagerSocket;
}

CServerSocket::~CServerSocket()
{
}


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

/////////////////////////////////////////////////////////////////////////////
// CServerSocket member functions

void CServerSocket::OnAccept(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
/*
	m_sockClient = new CClientSocket();

	if(!Accept(*m_sockClient))
	{
		AfxMessageBox("Accept异常");
		delete m_sockClient;
		m_sockClient = NULL;
		return;
	}
	m_sockQueue.AddTail(m_sockClient);
*/
	CAsyncSocket::OnAccept(nErrorCode);
	m_pManagerSocket->AcceptClient();
}
/*
void CServerSocket::StartServer()
{
	CCmppGatewayDlg *pDlg = new CCmppGatewayDlg();
	Create(pDlg->m_nPort, SOCK_STREAM);
	if(!Listen())
	{
		AfxMessageBox("Server侦听异常");
		return;
	}

	POSITION pos = m_sockQueue.GetHeadPosition();
	while(pos!=NULL)
	{
		CClientSocket* client = (CClientSocket *)m_sockQueue.GetAt(pos);
		m_sockQueue.RemoveAt(pos);
		delete client;
	}

	delete pDlg;
}
/*
UINT ReceiveThread(LPVOID lpParam)
{
	char buffer[1024];
	CServerSocket *sock = (CServerSocket *)lpParam;
	while(sock->m_bRev)
	{
		int count = sock->m_sockClient.Receive(buffer, sizeof(buffer), 0);
		if(count>0)
		{
			buffer[count] = NULL;
			sock->m_cCmppMsg.DecodeMessage(buffer);
			sock->CheckReceiveMsg(&sock->m_cCmppMsg);
		}
		Sleep(10);
	}
	return 0;
}
*/

⌨️ 快捷键说明

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