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


C++ TcpConnection::GetSocket方法代码示例

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


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

示例1: MessagePtr

void 
NetClient::onGroupPrepare( MessagePtr m )
{
	K_ASSERT( m_groupId == 0 );
	K_ASSERT( m_selfTag == 0 );

	m_groupId = 0;
	m_selfTag = 0;

	NmGroupPrepare* gp = static_cast<NmGroupPrepare*>( m.Get() );

	TcpConnection* c = m_tcp.FindById( gp->remote );

	if ( c == 0 )
	{
		LOG( FT_WARN, 
			 _T("NetClient::onGroupPrepare> Connection %d not found"), 
			 gp->remote );

		return;
	}
	
	m_udp.Fini();

	m_groupId = gp->groupId;
	m_selfTag = gp->connectionId;

	// init udp with c as a relay connection 
	// use same ip:port as TCP connection
	bool rc = m_udp.Init( this, 
						  &m_ios, 
						  c->GetSocket()->GetAddress(), 
						  m_selfTag, 
						  gp->sl, 
						  gp->challenge, 
						  c );

	if ( !rc )
	{
		LOG( FT_WARN, _T("NetClient::onGroupPrepare> Failed to init udp") );

		return;
	}

	NmGroupPrepared* p = new NmGroupPrepared;

	p->remote 		= gp->remote;
	p->groupId 		= gp->groupId;
	p->connectionId = gp->connectionId;
	p->in 			= c->GetSocket()->GetAddress();

	m_tcp.Send( m->remote, MessagePtr( p ) );

	LOG( FT_DEBUG, _T("NetClient::onGroupPrepare> Prepared group %d connection %d"), 
		 gp->groupId, 
		 gp->connectionId );
}
开发者ID:criptych,项目名称:gamekernel,代码行数:57,代码来源:NetClient.cpp

示例2:

void
NetServer::onJoinUdpGroup( const NetGroupOp& op )
{
	NetGroupMap::iterator i = m_groups.find( op.groupId );

	if ( i == m_groups.end() )
	{
		LOG( FT_WARN, _T("NetServer::onJoinUdpGroup> %d not found"), op.groupId );

		// TODO: error report

		return;
	}

	TcpConnection* c = m_tcp.FindById( op.connectionId );

	if ( c == 0 )
	{
		LOG( FT_WARN, 
			 _T("NetServer::onJoinUdpGroup> Connection %d not found"), 
			 op.connectionId );

		return;
	}

	NetGroup* group = i->second;
	K_ASSERT( group != 0 );

	c->SetGroup( op.groupId );

	(void)group->Join( op.connectionId, c->GetSocket()->GetPeerAddress(), op.extra );

	LOG( FT_DEBUG, 
		 _T("NetServer::onJoinUdpGroup> %d joined to %d"), 
		 op.connectionId, group->GetId() );
}
开发者ID:criptych,项目名称:gamekernel,代码行数:36,代码来源:NetServer.cpp


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