Dynamic size of network package.

Started by
1 comment, last by qwedcxza 21 years, 7 months ago
In program, I must indicate a size of network data when I want receive it, I think the network messages of my program is not always fix size. Maybe I can send size of message before send it, then I can get size of every messages. Have other ways? Thank you.
Advertisement
quote:Original post by qwedcxza

In program, I must indicate a size of network data when I want receive it, I think the network messages of my program is not always fix size. Maybe I can send size of message before send it, then I can get size of every messages.

Have other ways? Thank you.


I believe that indicates the size of the buffer you are passing, so that it doesn''t overwrite memory by copying 1500 bytes into a 500 byte buffer.

It would be best to allocate 1500 bytes and pass 1500, then get the real size from the receive call.
If you''re using TCP streaming sockets, you''ll probably have to send the size of your data prior to the data itself.

If you''re using UDP datagrams, the size of each datagram is returned when you recv, but if the data is embedded together with other stuff in the datagram, you''ll have to send the data size anyway.

This topic is closed to new replies.

Advertisement