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


C++ Packet::GetLength方法代码示例

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


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

示例1: SOCK_SendPacket

int SOCK_SendPacket(SOCKET socket, Packet& packet, unsigned long protover, bool extended)
{
	if(!extended)
	{
		if(!packet.GetLength()) return 0;
		uint8_t* data = new uint8_t[packet.GetLength()];
		uint32_t size = packet.GetLength();
		std::vector<uint8_t> tbuf = packet.GetBuffer();
		for(uint32_t i = 0; i < size; i++)
			data[i] = tbuf[i];

		int ret_code = send_msg(socket, protover, data, size, 1);
		delete[] data;
		if(ret_code == -2) return SERR_TIMEOUT;
		if(ret_code == -1) return SERR_CONNECTION_LOST;
		return 0;
	}
	else
	{
		uint8_t* data = new uint8_t[packet.GetLength()+8];
		*(uint32_t*)(data) = packet.GetLength();
		*(uint32_t*)(data+4) = 0x80100000;
		std::vector<uint8_t> tbuf = packet.GetBuffer();
		for(uint32_t i = 0; i < packet.GetLength(); i++)
			data[i+8] = tbuf[i];

		int ret_code = send(socket, (const char*)data, packet.GetLength()+8, 0);
		delete[] data;
		if(ret_code == -1) return SERR_CONNECTION_LOST;
		return 0;
	}
}
开发者ID:jewalky,项目名称:srvmgr,代码行数:32,代码来源:socket.cpp

示例2: UserLogout

    void LoginClientConn::UserLogout(const string &user_id) {
        proto::IMServerUserLogoutRequest logout_req;
        logout_req.set_user_id(user_id);

        Packet packet;
        PacketSetPBMsg(&packet, &logout_req);
        packet.SetVersion(IM_PROTO_VERSION);
        packet.SetServiceId(proto::SID_SERVER);
        packet.SetCommandId(proto::CID_SERVER_REQ_USERLOGOUT);
        // TODO seq num
        packet.SetSeqNum(0);

        // TODO can add to wait for logout ack list
        Send(packet.GetBuffer(), packet.GetLength());
    }
开发者ID:wenwenyyw,项目名称:learn-cpp,代码行数:15,代码来源:login_client_conn.cpp

示例3: ReceivePacket

bool CarModel::ReceivePacket(Packet * packet)
{
	std::map<in_addr_t, std::vector<SafetyPacket> >::iterator iterMessage;
	bool bValid = false;
	Packet * pNewPacket;

	packet->m_ID.iRXSeqNumber = GetNextRXSequenceNumber();
	if (m_pPhysModel != NULL && m_pPhysModel->ReceivePacket(packet))
	{
		if (m_pLinkModel != NULL && m_pLinkModel->ReceivePacket(packet))
		{
			unsigned int iBytesPerSec = GetTXRate();
			pNewPacket = packet->clone();
			struct timeval tTransmit = iBytesPerSec > 0 ? MakeTime((double)pNewPacket->GetLength() / iBytesPerSec) : timeval0;
			g_pSimulator->m_EventQueue.AddEvent(SimEvent(pNewPacket->m_tRX - tTransmit, EVENT_PRIORITY_HIGHEST, QString::null, m_strModelName, EVENT_CARMODEL_RXMESSAGEBEGIN, pNewPacket, DestroyPacket));
			bValid = true;
		}
	}

	return bValid;
}
开发者ID:PennTao,项目名称:GrooveNet,代码行数:21,代码来源:CarModel.cpp

示例4: SendPacket

	void Client::SendPacket(Packet &packet)
	{
		ENetPacket *enetPacket = enet_packet_create(packet.GetData(), packet.GetLength(), ENET_PACKET_FLAG_RELIABLE);
		enet_peer_send(_peer, 0, enetPacket);
	}
开发者ID:uberpixel,项目名称:Ur,代码行数:5,代码来源:URClient.cpp


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