当前位置: 首页>>代码示例>>C++>>正文


C++ CSocket::GetSockName方法代码示例

本文整理汇总了C++中CSocket::GetSockName方法的典型用法代码示例。如果您正苦于以下问题:C++ CSocket::GetSockName方法的具体用法?C++ CSocket::GetSockName怎么用?C++ CSocket::GetSockName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CSocket的用法示例。


在下文中一共展示了CSocket::GetSockName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ListSockets

void CModule::ListSockets() {
	if (m_sSockets.empty()) {
		PutModule("You have no open sockets.");
		return;
	}

	CTable Table;
	Table.AddColumn("Name");
	Table.AddColumn("State");
	Table.AddColumn("LocalPort");
	Table.AddColumn("SSL");
	Table.AddColumn("RemoteIP");
	Table.AddColumn("RemotePort");

	set<CSocket*>::iterator it;
	for (it = m_sSockets.begin(); it != m_sSockets.end(); ++it) {
		CSocket* pSocket = *it;

		Table.AddRow();
		Table.SetCell("Name", pSocket->GetSockName());

		if (pSocket->GetType() == CSocket::LISTENER) {
			Table.SetCell("State", "Listening");
		} else {
			Table.SetCell("State", (pSocket->IsConnected() ? "Connected" : ""));
		}

		Table.SetCell("LocalPort", CString(pSocket->GetLocalPort()));
		Table.SetCell("SSL", (pSocket->GetSSL() ? "yes" : "no"));
		Table.SetCell("RemoteIP", pSocket->GetRemoteIP());
		Table.SetCell("RemotePort", (pSocket->GetRemotePort()) ? CString(pSocket->GetRemotePort()) : CString(""));
	}

	PutModule(Table);
}
开发者ID:stevestreza,项目名称:ZNC-Node,代码行数:35,代码来源:Modules.cpp

示例2: FindSocket

CSocket* CModule::FindSocket(const CString& sSockName) {
	set<CSocket*>::iterator it;
	for (it = m_sSockets.begin(); it != m_sSockets.end(); ++it) {
		CSocket* pSocket = *it;
		if (pSocket->GetSockName().Equals(sSockName)) {
			return pSocket;
		}
	}

	return NULL;
}
开发者ID:stevestreza,项目名称:ZNC-Node,代码行数:11,代码来源:Modules.cpp

示例3: RemSocket

bool CModule::RemSocket(const CString& sSockName) {
	set<CSocket*>::iterator it;
	for (it = m_sSockets.begin(); it != m_sSockets.end(); ++it) {
		CSocket* pSocket = *it;

		if (pSocket->GetSockName().Equals(sSockName)) {
			m_sSockets.erase(it);
			m_pManager->DelSockByAddr(pSocket);
			return true;
		}
	}

	return false;
}
开发者ID:stevestreza,项目名称:ZNC-Node,代码行数:14,代码来源:Modules.cpp

示例4: OnAccept

void CIPServer::OnAccept(int nErrorCode)
{
	CCardSwipeServiceApp* pApp = (CCardSwipeServiceApp*)AfxGetApp();
	CSocket newSocket;
	SOCKADDR saddr;
	char ch[96];
	CString sAddress;
	CString sIPAddress, sError;
	long nCardReaderId = -1;
	int iReturn;

	this->Accept(newSocket);
	memset(&saddr,0,sizeof(SOCKADDR));
	int iLen = sizeof(saddr);
	newSocket.GetSockName(&saddr,&iLen);
	// get dotted ip address
	lstrcpyA(ch,inet_ntoa(((SOCKADDR_IN*)&saddr)->sin_addr));
	sIPAddress = ch;
	sAddress.Format("%s:%d",ch,((SOCKADDR_IN*)&saddr)->sin_port);

	// is this address in the database?
	OysterClassLibrary::IOysterPtr pOyster;
	OysterClassLibrary::ICardReaderPtr pCardReader;

	HRESULT hr = pOyster.CreateInstance(OysterClassLibrary::CLSID_Oyster);
	if (hr != ERROR_SUCCESS)
	{
		GetLastErrorString(sError,hr);
		throw CGeneralException("CIPServer::OnAccept","Could not create OysterClassLibrary object (%d): %s",hr,sError);
	}

	memset(ch,0,sizeof(ch));
	iReturn = newSocket.Receive(ch,sizeof(ch));
	if (iReturn <= 0)
	{
		// either closed or an error occured
		GetError(sError,iReturn);
		throw CGeneralException("CIPServer::OnAccept","Receive function failed (%d): %s",iReturn,sError);
	}
	nCardReaderId = (long)&ch[0];
	pCardReader = pOyster->GetCardReaderById(nCardReaderId);
	if (pCardReader)
	{
		CVirtualCardReaderSocket* pNewSocket = new CVirtualCardReaderSocket(nCardReaderId);
		pNewSocket->Attach(newSocket.m_hSocket);
		newSocket.Detach();
		pNewSocket->Send(ECMD_COMMANDSTRING[ECMD_CONNECTSUCCESS],strlen(ECMD_COMMANDSTRING[ECMD_CONNECTSUCCESS]));
		pApp->m_mapCardSwipeIdToCardSwipe
		pApp->m_vClients.push_back(pNewSocket);
		DebugTell(_T("New client connection from %s\n"),(LPCTSTR)sAddress);
	}
	else
	{
		// invalid connection, send notification
		newSocket.Send(ECMD_COMMANDSTRING[ECMD_ERRORCONNECT],strlen(ECMD_COMMANDSTRING[ECMD_ERRORCONNECT]));
	}
	pOyster.Release();

	UNREFERENCED_PARAMETER(nErrorCode);

	CSocket::OnAccept(nErrorCode);
}
开发者ID:CarverLab,项目名称:Oyster,代码行数:62,代码来源:IPServer.cpp


注:本文中的CSocket::GetSockName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。