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


C++ NetworkMessage::Size方法代码示例

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


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

示例1: SendMessage

	void SendMessage(MessageConnection *connection)
	{
		NetworkMessage *msg = connection->StartNewMessage(191 /*A custom message number*/, 
		                                                  4 + extraBytes + 4 /*size of this message in bytes*/);
		msg->priority = 100;
		msg->reliable = true;
		msg->inOrder = true;
		msg->contentID = 1;
		DataSerializer ds(msg->data, msg->Size());
		++lastMessageNumber;
		ds.Add<u32>(lastMessageNumber);

		u32 checksum = 0;
		for(int i = 0; i < extraBytes; ++i)
		{
			u8 byte = (u8)rand();
			ds.Add<u8>(byte);

			// Just run some bit-twiddling algorithm over all the bits to generate a checksum.
			checksum ^= byte;
			checksum <<= NumBitsSet(byte);
		}
		ds.Add<u32>(checksum);
		connection->EndAndQueueMessage(msg);
	}
开发者ID:aoighost,项目名称:kNet,代码行数:25,代码来源:InOrderTest.cpp

示例2: BroadcastMessage

void NetworkServer::BroadcastMessage(unsigned long id, bool reliable, bool inOrder, unsigned long priority, 
                                     unsigned long contentID, const char *data, size_t numBytes,
                                     MessageConnection *exclude)
{
	PolledTimer timer;
	Lockable<ConnectionMap>::LockType clientsLock = clients.Acquire();
	if (timer.MSecsElapsed() >= 50.f)
	{
		LOG(LogWaits, "NetworkServer::BroadcastMessage: Accessing the connection list took %f msecs.",
			timer.MSecsElapsed());
	}

	for(ConnectionMap::iterator iter = clientsLock->begin(); iter != clientsLock->end(); ++iter)
	{
		MessageConnection *connection = iter->second;
		assert(connection);
		if (connection == exclude || !connection->IsWriteOpen())
			continue;

		NetworkMessage *msg = connection->StartNewMessage(id, numBytes);
		msg->reliable = reliable;
		msg->inOrder = inOrder;
		msg->priority = priority;
		msg->contentID = contentID;
		assert(msg->data);
		assert(msg->Size() == numBytes);
		memcpy(msg->data, data, numBytes);
		connection->EndAndQueueMessage(msg);
	}
}
开发者ID:AGreatFish,项目名称:Urho3D,代码行数:30,代码来源:NetworkServer.cpp

示例3: SendPingReplyMessage

	void SendPingReplyMessage(MessageConnection *connection, const char *receivedPingData, size_t receivedPingDataNumBytes)
	{
		DataDeserializer dd(receivedPingData, receivedPingDataNumBytes);
		NetworkMessage *msg = connection->StartNewMessage(customPingReplyMessageId, 2);
		msg->priority = 100;
		msg->reliable = false;
		DataSerializer ds(msg->data, msg->Size());
		u16 pingNumber = dd.Read<u16>();
		ds.Add<u16>(pingNumber);
		connection->EndAndQueueMessage(msg);
		cout << "Received PING_" << pingNumber << ". Sent PONG_" << pingNumber << "." << endl;
	}
开发者ID:aoighost,项目名称:kNet,代码行数:12,代码来源:LatencyTest.cpp

示例4: SendPingMessage

	void SendPingMessage(MessageConnection *connection)
	{
		NetworkMessage *msg = connection->StartNewMessage(customPingMessageId, 2);
		msg->priority = 100;
		msg->reliable = false;
		DataSerializer ds(msg->data, msg->Size());
		++sentPingNumber;
		ds.Add<u16>(sentPingNumber);
		connection->EndAndQueueMessage(msg);
		pingSendTime = Clock::Tick();
		cout << "Sent PING_" << sentPingNumber << "." << endl;
	}
开发者ID:aoighost,项目名称:kNet,代码行数:12,代码来源:LatencyTest.cpp

示例5: SendMessage

void MessageConnection::SendMessage(unsigned long id, bool reliable, bool inOrder, unsigned long priority,
                                    unsigned long contentID, const char *data, size_t numBytes)
{
    AssertInMainThreadContext();

    NetworkMessage *msg = StartNewMessage(id, numBytes);
    if (!msg)
    {
        LOG(LogError, "MessageConnection::SendMessage: StartNewMessage failed! Discarding message send.");
        return;
    }
    msg->reliable = reliable;
    msg->inOrder = inOrder;
    msg->priority = priority;
    msg->contentID = contentID;
    assert(msg->data);
    assert(msg->Size() == numBytes);
    memcpy(msg->data, data, numBytes);
    EndAndQueueMessage(msg);
}
开发者ID:r8d8,项目名称:Urho3D,代码行数:20,代码来源:MessageConnection.cpp

示例6: SenderMainLoopIteration

void NetworkApp::SenderMainLoopIteration()
{
	if (connection->IsWriteOpen())
	{
		connection->Process();

		// Add new data fragments into the queue.
		const int outboundMsgQueueSize = 1000;
		int i = outboundMsgQueueSize - connection->NumOutboundMessagesPending();
		while(i-- > 0 && connection->IsWriteOpen() && bytesSent < fileSize)
		{
			// File payload data bytes in this message.
			const size_t bytesInThisFragment = min((int)fragmentSize, fileSize - bytesSent);

			NetworkMessage *msg = connection->StartNewMessage(cFileTransferFragment, bytesInThisFragment+4);
			msg->priority = 100;
			msg->reliable = true;
			msg->inOrder = true;
#ifdef KNET_NETWORK_PROFILING
			msg->profilerName = "File (31)";
#endif

			DataSerializer ds(msg->data, msg->Size());
			ds.Add<u32>(nextFragment++);

#ifndef NULLTRANSFER
			size_t read = fread(ds.GetData() + ds.BytesFilled(), sizeof(char), bytesInThisFragment, handle);
#else
			size_t read = bytesInThisFragment;
#endif
			if (read < bytesInThisFragment)
			{
				LOG(LogUser, "Failed to read file!");
				connection->Close(0);
			}
			connection->EndAndQueueMessage(msg);
			bytesSent += bytesInThisFragment;
		}

		// If we've put out all file fragments to the network, close the connection down.
		if (connection->IsWriteOpen() && bytesSent >= fileSize && connection->NumOutboundMessagesPending() == 0)
		{
			LOG(LogUser, "All data sent. Disconnecting.");
			connection->Disconnect(15000);
		}

		if (statsPrintTimer.Test())
		{
			const tick_t sendFinishTick = Clock::Tick();
			double timespan = (float)Clock::TimespanToSecondsD(transferStartTick, sendFinishTick);
			LOG(LogUser, "Sending fragment %d. Elapsed: %.2f seconds. Bytes sent: %d. Transfer rate: %s/sec.", 
				nextFragment-1, (float)timespan, bytesSent, FormatBytes((bytesSent/timespan)).c_str());
			connection->DumpStatus();
			statsPrintTimer.StartMSecs((float)printIntervalMSecs);
		}
	}

	if (!connection->IsReadOpen() && (connection->NumOutboundMessagesPending() == 0 || !connection->IsWriteOpen()))
	{
		connection->Close(15000);
		fclose(handle);
		QApplication::quit();
	}
	else
		QTimer::singleShot(10, this, SLOT(SenderMainLoopIteration()));
}
开发者ID:aoighost,项目名称:kNet,代码行数:66,代码来源:FileTransfer.cpp


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