本文整理汇总了C++中CSocket::Socket方法的典型用法代码示例。如果您正苦于以下问题:C++ CSocket::Socket方法的具体用法?C++ CSocket::Socket怎么用?C++ CSocket::Socket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSocket
的用法示例。
在下文中一共展示了CSocket::Socket方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Run
void CServer::Run()
{
Init();
CSocket sock;
if(!sock.Socket()) return;
if(!sock.Bind( CConfig::GetInstance()->GetPortPID(ID_SERVER), CConfig::GetInstance()->GetAddrPID(ID_SERVER)) ) return;
cout << "listening.." << endl;
sock.Listen();
CWireThread* pThreadWire = new CWireThread();
pThreadWire->Start();
CGateThread* pThreadGate = new CGateThread();
pThreadGate->Start();
if(!sock.Accept(m_sockMain)) return;
if(!sock.Accept(m_sockOT)) return;
sock.Close();
cout << "accepted sockets!" << endl;
COTThread* pThreadOT = new COTThread();
pThreadOT->Start();
RunMainThread();
m_sockMain.Close();
pThreadOT->Wait();
m_sockOT.Close();
pThreadGate->Wait();
pThreadWire->Wait();
Cleanup();
delete pThreadOT;
delete pThreadGate;
delete pThreadWire;
}
示例2: ShutdownServer
void CClientManager::ShutdownServer( IN_ADDR addrHost, bool bForward )
{
CSocket sock;
sock.Socket( SOCK_DGRAM );
if( addrHost.s_addr==INADDR_ANY ){
//send shutdown message to all the known host addresses
CObjLocker<CClientManager> locker(this);
set<IN_ADDR>::iterator pos;
for( pos=m_HostAddrs.begin(); pos!=m_HostAddrs.end(); ++pos ){
CMessageBase msg;
msg.Init( NCM_SHUTDOWN, CSessionAddr(GetLocalInAddr(), 0), CSessionAddr(*pos, 0), bForward );
CSockAddrIn dstaddr( *pos, NCP_SERVER_PING_PORT );
SendMessageTo( sock, &msg, dstaddr );
}
}else{
//send shutdown to a specific addresse
CMessageBase msg;
msg.Init( NCM_SHUTDOWN, CSessionAddr(GetLocalInAddr(), 0), CSessionAddr(addrHost, 0), bForward );
CSockAddrIn dstaddr( addrHost, NCP_SERVER_PING_PORT );
SendMessageTo( sock, &msg, dstaddr );
}
}