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


C++ TCPSocket::Open方法代码示例

本文整理汇总了C++中TCPSocket::Open方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPSocket::Open方法的具体用法?C++ TCPSocket::Open怎么用?C++ TCPSocket::Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TCPSocket的用法示例。


在下文中一共展示了TCPSocket::Open方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Init

void LRTGroupSession::Init()
{
    TCPSocket* socket = this->GetSocket();

    socket->Open();

    socket->InitNonBlocking(socket->GetSocketFD());
    socket->NoDelay();
    socket->KeepAlive();
    socket->SetSocketBufSize(96L * 1024L);

    socket->SetTask(this);
    this->SetTimer(120*1000);
    for(int i=0;i<MSG_PACKED_ONCE_NUM;++i)
    {
         m_packedNewMsg.add_msgs();
    }
    for(int i=0;i<MSG_PACKED_ONCE_NUM;++i)
    {
         m_packedSeqnMsg.add_msgs();
    }
    for(int i=0;i<MSG_PACKED_ONCE_NUM;++i)
    {
         m_packedDataMsg.add_msgs();
    }

}
开发者ID:BoYuanZjq,项目名称:Teameeting-MsgServer,代码行数:27,代码来源:LRTGroupSession.cpp

示例2: Init

void MRTTransferSession::Init()
{
    TCPSocket* socket = this->GetSocket();

    socket->Open();

    socket->InitNonBlocking(socket->GetSocketFD());
    socket->NoDelay();
    socket->KeepAlive();
    socket->SetSocketBufSize(96L * 1024L);

    this->SetTimer(120*1000);
}
开发者ID:BoYuanZjq,项目名称:Teameeting-MsgServer,代码行数:13,代码来源:MRTTransferSession.cpp

示例3: ConnHttpHost

bool RTHttpSender::ConnHttpHost(const std::string& addr, const unsigned short port, const std::string& host)
{
    SetHttpHost(host);
    TCPSocket* socket = this->GetSocket();
    if (socket->Open() != OS_NoErr) {
        LE("%s socket->Open failed!!!\n", __FUNCTION__);
        return false;
    }
    socket->InitNonBlocking(socket->GetSocketFD());
    socket->NoDelay();
    socket->SetSocketBufSize(96L * 1024L);
    socket->SetTask(this);
    this->SetTimer(5*1000);
    OS_Error err;
    do{
        sleep(1);
        err = socket->Connect(SocketUtils::ConvertStringToAddr(addr.c_str()), port);
        LI("Connect to http server %s:%u, waiting...\n", addr.c_str(), port);
    }while(!(err==OS_NoErr || err==EISCONN));
        
    //socket->RequestEvent(EV_RE);
    LI("%s addr:%s, port:%u\n", __FUNCTION__, addr.c_str(), port);
    return true;
}
开发者ID:DyncEric,项目名称:Teameeting-MsgServer,代码行数:24,代码来源:RTHttpSender.cpp

示例4: main

int main(int argc, char** argv)
{
	// use non-default port if provided
	if (argc > 1)
		*(const_cast<unsigned short*>(&SERVER_PORT)) = atoi(argv[1]);
	
	if (!Init())
	{
		printf("Failed to initialize.\n");
		return 1;
	}
	
	// prepare for peer to peer
	PeerAuthClientState aPeerAuthClientState;
	unsigned short aRequestBufLen = 0;
	const void* aRequestBufP = NULL;

	// create Auth1Request
	Error aError = aPeerAuthClientState.Init(gIdentity, &aRequestBufP, &aRequestBufLen);
	printf("PeerAuthClientState::Init: %s.\n", WONErrorToString(aError));
	if (aError != Error_Success) return aError;

	// connect to server
	IPSocket::Address aServerAddress("localhost", SERVER_PORT);
	TCPSocket aServerCommSocket;
	aError = aServerCommSocket.Open(aServerAddress);
	printf("Connecting to server at %s: %s.\n", aServerAddress.GetAddressString().c_str(), WONErrorToString(aError));
	if (aError != Error_Success) return aError;

	// send Auth1Request
	aServerCommSocket.Send(2, &aRequestBufLen);
	aServerCommSocket.Send(aRequestBufLen, aRequestBufP);
	printf("Sent request.\n");

	// receive server response (Auth1Challenge1 or Auth1Complete)
	unsigned short aChallenge1BufLen = 0;
	aServerCommSocket.Recv(2, &aChallenge1BufLen);
	void* aChallenge1BufP = new unsigned char[aChallenge1BufLen];
	aServerCommSocket.Recv(aChallenge1BufLen, aChallenge1BufP);
	printf("Received server->client challenge.\n");

	// process server response:
	//  if Auth1Complete, we're done
	//  if Auth1Challenge1, generate Auth1Challenge2
	unsigned short aChallenge2BufLen = 0;
	const void* aChallenge2BufP = NULL;
	aPeerAuthClientState.RecvChallenge1(aChallenge1BufP, aChallenge1BufLen,
	                                    &aChallenge2BufP, &aChallenge2BufLen);
	printf("PeerAuthClientState::RecvChallenge1: %s.\n", WONErrorToString(aError));
	if (aError != Error_Success) return aError;

	// send Auth1Challenge2
	aServerCommSocket.Send(2, &aChallenge2BufLen);
	aServerCommSocket.Send(aChallenge2BufLen, aChallenge2BufP);
	printf("Sent client->server challenge.\n");

	// receive Auth1Complete
	unsigned short aResultBufLen = 0;
	aServerCommSocket.Recv(2, &aResultBufLen);
	void* aResultBufP = new unsigned char[aResultBufLen];
	aServerCommSocket.Recv(aResultBufLen, aResultBufP);	
	printf("Received result.\n");

	// process Auth1Complete
	aError = aPeerAuthClientState.RecvResult(aResultBufP, aResultBufLen);
	printf("PeerAuthClientState::RecvResult: %s.\n", WONErrorToString(aError));
	return aError;
}
开发者ID:SOLARIC,项目名称:world-opponent-network,代码行数:68,代码来源:P2PClient.cpp


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