本文整理汇总了C++中CSocket::Listen方法的典型用法代码示例。如果您正苦于以下问题:C++ CSocket::Listen方法的具体用法?C++ CSocket::Listen怎么用?C++ CSocket::Listen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSocket
的用法示例。
在下文中一共展示了CSocket::Listen方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Rusock
int Rusock()
{
unlink("./USOCK");
CSocket sock;
nRet = sock.Listen("./USOCK");
if (nRet < 0)
{
printf("Listen failed:%s \n", strerror(errno));
return -1;
}
int fd = sock.Accept();
if (nRet < 0)
{
printf("Accept failed:%s \n", strerror(errno));
return -1;
}
while (true)
{
if (_HandleSignal() < 0)
break;
gettimeofday(&time_a, NULL);
nRet = read(fd, rbuff, g_len);
gettimeofday(&time_b, NULL);
struct timeval *time_w = (struct timeval *)(rbuff);
if (nRet != g_len)
{
printf("read fialed nRet %d %s\n", nRet, strerror(errno));
break;
}
g_count0++;
if(g_verify == 1)
{
struct data* d = (struct data* )(rbuff+sizeof(struct timeval));
if( d->compare() < 0)
{
printf("format error %s\n");fflush(NULL);
}
}
unsigned long long use_time0 = (time_b.tv_sec - time_a.tv_sec) * 1000000 + (time_b.tv_usec - time_a.tv_usec);
total_time0 += use_time0;
unsigned long long delay_time = (time_b.tv_sec - time_w->tv_sec) * 1000000 + (time_b.tv_usec - time_w->tv_usec);
if(delay_time < 10000)
{
if(delay_time > g_delay_max)
g_delay_max = delay_time;
recv_delay_count0++;
recv_delay0 += delay_time;
}
}
return 0;
}
示例2: CreateSocketServer
CSocket* CTransferSocket::CreateSocketServer(int port)
{
CSocket* pServer = new CSocket(engine_.GetThreadPool(), this);
int res = pServer->Listen(controlSocket_.m_pSocket->GetAddressFamily(), port);
if (res) {
controlSocket_.LogMessage(MessageType::Debug_Verbose, _T("Could not listen on port %d: %s"), port, CSocket::GetErrorDescription(res));
delete pServer;
return 0;
}
SetSocketBufferSizes(pServer);
return pServer;
}
示例3: CreateSocketServer
CSocket* CTransferSocket::CreateSocketServer(int port)
{
CSocket* pServer = new CSocket(this);
int res = pServer->Listen(m_pControlSocket->m_pSocket->GetAddressFamily(), port);
if (res)
{
m_pControlSocket->LogMessage(::Debug_Verbose, _T("Could not listen on port %d: %s"), port, CSocket::GetErrorDescription(res).c_str());
delete pServer;
return 0;
}
SetSocketBufferSizes(pServer);
return pServer;
}
示例4: 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;
}
示例5: main
void main()
{
AfxSocketInit();
CSocket sock;
int n = sock.Create(PORT1);
if(!n)
{
cout << "创建句柄失败:" << GetLastError() << endl;
return;
}
sock.Listen();
while (true)
{
CSocket socka;
n = sock.Accept(socka);
if(!n)
{
cout << "接受对方连接失败:" << GetLastError() << endl;
return;
}
while (true)
{
char s[256];
n = socka.Receive(s,sizeof(s));
if(SOCKET_ERROR == n)
{
cout << "接收数据失败:" << GetLastError() << endl;
break;
}
if(!n)
{
cout << "结束接收数据,句柄关闭!" << endl;
break;
}
cout << s <<endl;
}
socka.Close();
}
}