[英]Universal variable for different sizes
I do some recv()
and send()
on sockets and I know the maximum packetSize
is 256 MB
.我在套接字上做了一些
recv()
和send()
,我知道最大packetSize
是256 MB
。
Does it exist some variable which finds out the length of the packet and allocates that space?它是否存在一些变量来找出数据包的长度并分配该空间?
I mean我的意思是
packetSize
is just 1045 B
, allocate that sizepacketSize
仅为1045 B
,分配该大小packetSize
is 56 MB
, allocate that sizepacketSize
为56 MB
,分配该大小Thanks!谢谢!
What you're looking for is std::vector
.您正在寻找的是
std::vector
。 It can contain an arbitrary number of elements.它可以包含任意数量的元素。
Finds out the length of the packet
找出包的长度
Are you sure you did not mean length of the message?你确定你不是指消息的长度? Also may depend on what protocol you use.
也可能取决于您使用的协议。
Assuming a streaming protocol such as TCP, you can't really know until you receive the data.假设使用 TCP 等流协议,在收到数据之前您无法真正知道。 If your vector wasn't big enough, then resize and keep receiving until you have gotten all of it (or until you reach some safety limit to mitigate denial of service attacks).
如果您的向量不够大,则调整大小并继续接收,直到您获得所有向量(或直到达到某个安全限制以减轻拒绝服务攻击)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.