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

📄 sgiplistensocket.cpp

📁 1、自己编写的遵循SGIP1.1协议的短信客户端程序。仅供测试、学习。 2、该程序只实现了SGIP1.1协议的一部分。
💻 CPP
字号:
// SgipListenSocket.cpp : implementation file
//

#include "stdafx.h"
#include "SgipServiceDemo.h"
#include "SgipListenSocket.h"
#include "SocketResource.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSgipListenSocket

CSgipListenSocket::CSgipListenSocket()
{

}

CSgipListenSocket::~CSgipListenSocket()
{
}


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

/////////////////////////////////////////////////////////////////////////////
// CSgipListenSocket member functions
int CSgipListenSocket::Listen(UINT uPort)
{
	m_uiPort = uPort;

	if (!CAsyncSocket::Create(uPort))
		return GetLastError();
	if (!CAsyncSocket::Listen())
		return GetLastError();
	return 0;
}

void CSgipListenSocket::OnAccept(int nErrorCode) 
{
	//CAsyncSocket::OnAccept(nErrorCode);
	// TODO: Add your specialized code here and/or call the base class
	if(0 != nErrorCode) return;
	//get server connection that can use
	int iSocketNo;
	CSgipServerSocket * pServerSocket;

	m_pManager->Check();

	if(m_pManager->GetServerSocket(&iSocketNo,&pServerSocket) == 0)
	{
		if(!Accept(*pServerSocket))
		{
			TRACE("ListenOnAccept:Accept the serversocket fail!\n");
			pServerSocket->m_bConnected = FALSE;
		}
		else
		{
			TRACE("ListenOnAccept:Accept the serversocket ok!\n");
			pServerSocket->m_bConnected = TRUE;
			pServerSocket->m_strLocalUserName = m_pManager->m_ini_def.strLocalUserName;
			pServerSocket->m_strLocalPwd = m_pManager->m_ini_def.strLocalPwd;
		}
	}
	else
	{
		TRACE("ListenOnAccept:No can use serversocket!\n");
		//随便给个socket,然后就把它关掉!!
		CAsyncSocket *pTempSocket = new CAsyncSocket();
		Accept(*pTempSocket);
		delete pTempSocket;
		//Close();
		//Detach();
		//Create();
		//Listen(m_uiPort);
	}
	return ;
}



void CSgipListenSocket::SetManager(CSocketResource *pManager)
{
	m_pManager = pManager;
}

⌨️ 快捷键说明

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