本文整理汇总了C++中NetworkPacket::putRawPacket方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkPacket::putRawPacket方法的具体用法?C++ NetworkPacket::putRawPacket怎么用?C++ NetworkPacket::putRawPacket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkPacket
的用法示例。
在下文中一共展示了NetworkPacket::putRawPacket方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testConnectSendReceive
//.........这里部分代码省略.........
UASSERT(hand_server.last_id == 2);
//sleep_ms(50);
while (client.Connected() == false) {
try {
NetworkPacket pkt;
infostream << "** running client.Receive()" << std::endl;
client.Receive(&pkt);
infostream << "** Client received: peer_id=" << pkt.getPeerId()
<< ", size=" << pkt.getSize() << std::endl;
} catch (con::NoIncomingDataException &e) {
}
sleep_ms(50);
}
sleep_ms(50);
try {
NetworkPacket pkt;
infostream << "** running server.Receive()" << std::endl;
server.Receive(&pkt);
infostream << "** Server received: peer_id=" << pkt.getPeerId()
<< ", size=" << pkt.getSize()
<< std::endl;
} catch (con::NoIncomingDataException &e) {
}
/*
Simple send-receive test
*/
{
NetworkPacket pkt;
pkt.putRawPacket((u8*) "Hello World !", 14, 0);
Buffer<u8> sentdata = pkt.oldForgePacket();
infostream<<"** running client.Send()"<<std::endl;
client.Send(PEER_ID_SERVER, 0, &pkt, true);
sleep_ms(50);
NetworkPacket recvpacket;
infostream << "** running server.Receive()" << std::endl;
server.Receive(&recvpacket);
infostream << "** Server received: peer_id=" << pkt.getPeerId()
<< ", size=" << pkt.getSize()
<< ", data=" << (const char*)pkt.getU8Ptr(0)
<< std::endl;
Buffer<u8> recvdata = pkt.oldForgePacket();
UASSERT(memcmp(*sentdata, *recvdata, recvdata.getSize()) == 0);
}
u16 peer_id_client = 2;
/*
Send a large packet
*/
{
const int datasize = 30000;
NetworkPacket pkt(0, datasize);
for (u16 i=0; i<datasize; i++) {
pkt << (u8) i/4;
}