本文整理汇总了C++中NetStreamStorage::writePacket方法的典型用法代码示例。如果您正苦于以下问题:C++ NetStreamStorage::writePacket方法的具体用法?C++ NetStreamStorage::writePacket怎么用?C++ NetStreamStorage::writePacket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetStreamStorage
的用法示例。
在下文中一共展示了NetStreamStorage::writePacket方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: length_storage
bool
NetStreamSocket::
receiveExact( NetStreamStorage &msg )
throw( NetStreamSocketException )
{
/* receive length of vector */
unsigned char * const bufLength = new unsigned char[4];
int bytesRead = 0;
int readThisTime = 0;
while (bytesRead<4)
{
readThisTime = recv( socket_, (char*)(bufLength + bytesRead), 4-bytesRead, 0 );
if( readThisTime <= 0 )
{
// BailOnNetStreamSocketError definitely throws an exception so clear up heap
delete[] bufLength;
BailOnNetStreamSocketError( "NetStreamSocket::receive() @ recv" );
}
bytesRead += readThisTime;
}
NetStreamStorage length_storage(bufLength,4);
int NN = length_storage.readInt() - 4;
/* receive vector */
unsigned char * const buf = new unsigned char[NN];
bytesRead = 0;
readThisTime = 0;
while (bytesRead<NN)
{
readThisTime = recv( socket_, (char*)(buf + bytesRead), NN-bytesRead, 0 );
if( readThisTime <= 0 )
{
// BailOnNetStreamSocketError definitely throws an exception so clear up heap
delete[] bufLength;
delete[] buf;
BailOnNetStreamSocketError( "netstream::NetStreamSocket::receive() @ recv" );
}
bytesRead += readThisTime;
}
msg.reset();
msg.writePacket(buf, NN);
if (verbose_)
{
cerr << "Rcvd Storage with " << 4 + NN << " bytes via netstream::NetStreamSocket: [";
for (int i=0; i < 4; ++i)
{
cerr << " " << (int)bufLength[i] << " ";
}
for (int i=0; i < NN; ++i)
{
cerr << " " << (int)buf[i] << " ";
}
cerr << "]" << endl;
}
delete[] buf;
delete[] bufLength;
return true;
}