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


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

本文整理汇总了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;
}
开发者ID:YangChunQuan,项目名称:Code,代码行数:59,代码来源:main_ipc.cpp

示例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;
}
开发者ID:zedfoxus,项目名称:filezilla-client,代码行数:14,代码来源:transfersocket.cpp

示例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;
}
开发者ID:Hellcenturion,项目名称:MILF,代码行数:15,代码来源:transfersocket.cpp

示例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;
	
} 
开发者ID:DBMI,项目名称:CountEverything,代码行数:44,代码来源:server.cpp

示例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();

	}
}
开发者ID:LeonLH,项目名称:hello-world,代码行数:42,代码来源:Source.cpp


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