Determining Data Size For Network Send/Rec :: Winsock

Started by
16 comments, last by kuphryn 21 years, 11 months ago
A byte is the smallest addressable piece of memory. On most platforms a byte is 8 bits and a char is the same size as a byte.
An integer is 4 bytes (at least on windows and i think linux) and a 4 byte unsigned integer can hold a value (number) up to just over 4 billion.
So an integer doesn hold up to 2^32 characters, it holds a number up to 2^32 and that will be the number of characters following in the stream.
So my program would proceed like this:

Read an integer (4 bytes) from the stream
(Lets say the integer is 23)]
Read 23 char''s (bytes) from the stream. this is the chat message

So the integer you send at the start doesn''t hold any data, it tells you how much data to read off the stream to get the chat message.
Advertisement
Ahh.

I understanding now. There is a distinction between what a *variable* can hold and what actual data size relative to characters.

A member recommended using 8 byte to check for the data size instead of 4 byte. Is there a long long data type holding 8 byte integer?

Kuphryn
Kindof, it depends on your compiler. I think gcc might have a 64-bit "long long" and i think MS VC++ uses __int64. I''m not 100% sure on these though, but check your compiler docs etc.
I really doubt you''d need to use more than a normal unsigned int though, as (particularly for a chat program) it is highly doubtful that you will, or will want to send over 4 gigabytes in a single message...
Okay. Thanks.

Kuphryn
LOL Yeah can you imagine sending a 4GB chat message. I guess it would go something like:

Bob: I''m sending you a binary dump of my harddrive
Neil: Nooooooooo....
Bob: @#)(*D_CVSD_) +@#$) )(* _@#$ etc

lol

Dire Wolf
www.digitalfiends.com
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
Gosh, I never thought of that application, I''m going to start using 64bit size holes (And I think you can fit 16 Exobytes into one of those, maybe the even the next size up)

It''s not entirely inconceivable that you would never want to send a message larger than 64k - suppose you want to do something like serialize and send an IMediaSample over the pipe for a digital CCTV application, so using 32bit isn''t a terrible idea. However, in most applications, you probably won''t send messages larger than 64k, so you can use a 16bit hole to store the size.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Honestly, I''d stick the limit at 255 characters (1 byte/8 bits). Anyone who types more than that many characters in a chat message needs to be shot anyway.

BTW, this doesn''t include message boards, where I''ve commonly been guilty of making posts in the 12-16000 character range :D
quote:(And I think you can fit 16 Exobytes into one of those, maybe the even the next size up)


Not sure if it''s Exobytes, but it''s 18 sextillion bytes, or maybe it''s pentillion, but I thought that they skipped pentillion and went from quadrillion to sextillion.

OK, just checked, it''s quintillion.

This topic is closed to new replies.

Advertisement