本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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);
}