本文整理汇总了C++中SockAddr::GetIPAndPortString方法的典型用法代码示例。如果您正苦于以下问题:C++ SockAddr::GetIPAndPortString方法的具体用法?C++ SockAddr::GetIPAndPortString怎么用?C++ SockAddr::GetIPAndPortString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SockAddr
的用法示例。
在下文中一共展示了SockAddr::GetIPAndPortString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ThreadRun
virtual void ThreadRun()
{
DWORD port = m_parent->ReadPortFromRegistry();
if ( port == 0 )
port = LUA_DEBUGGER_PORT;
LuaNetworkSocket socket;
if (!socket.Create(port)) // Auto pick a port if 0.
{
socket.Create(0); // Force auto pick.
}
m_parent->m_socketSockAddr = socket.GetSockName();
m_parent->m_socketSockAddr.GetPort();
m_parent->WritePortToRegistry();
SetEvent( m_socketCreatedEvent );
while (!ThreadExitTriggered())
{
if (!socket.IsReadDataWaiting())
{
Sleep(50);
continue;
}
SockAddr sockAddr;
LuaNetworkSocket inSocket = socket.Accept(&sockAddr);
if (!inSocket.IsValid())
{
Sleep(50);
continue;
}
#ifdef ULTRA_DEBUG
{
SockAddr::IPString ipAddr;
sockAddr.GetIPAndPortString(ipAddr);
SimpleString str = SimpleString("LuaNetworkClient: Incoming connection request from [") + ipAddr + "]\n";
OutputDebugStringA( str );
}
#endif ULTRA_DEBUG
EnterCriticalSection( &m_parent->m_socketAccessCS );
// The client allows only one server connection at a time.
m_parent->m_socket.Close();
m_parent->m_socket.Attach(inSocket);
inSocket.Attach(INVALID_SOCKET);
DWORD startTime = GetTickCount();
while ( GetTickCount() - startTime < 3000 )
{
DWORD count = m_parent->m_socket.GetReadDataWaiting();
if ( count < 4 )
{
Sleep(50);
continue;
}
char id[33];
memset(id, 0, sizeof(id));
m_parent->m_socket.ReadString(id, 32);
if (id == m_parent->m_id)
{
m_parent->OnConnect();
break;
}
m_parent->m_socket.Close();
break;
}
LeaveCriticalSection( &m_parent->m_socketAccessCS );
Sleep(50);
}
}