Determining Data Size For Network Send/Rec :: Winsock

kuphryn

Senior member
Jan 7, 2001
400
0
0
Hi.

I am studying networking programming from Network Programming For Microsoft Windows, Second Edition by Anthony Jones and Jim Ohlund. I am just about ready to start on a new product that will be my first real Winsock program. I want to design and implement a simple message program (chat) that work over the IP protocol and TCP protocol.

I have the basic program core design in my mind. However, I am stuck with one problem and it is a problem that even Jones and Ohlund implied could be difficult to overcome for inexperience network programmers.

How do you predetermine the size of the data you receive?

Winsock has two basic functions for receiving data: revc (IPv4 or Winsock 1.1+) and WSARecv (IPv6 or Winsock 2). WSARecv is a powerful tool for *predetermined* data size. You can send multiple packages at one time, but the data size must be predetermined (i.e. 10k, 20k, and finally 30k). I will probably use revc since it is more flexible. Even with recv, however, you must give a specific size (byte) to read. Jones and Ohlund recommend sends the size of the data in the first four byte of the data stream. However, what if the user wants to send something that is larger than what a bour byte char variable can hold?

Please post any possible solutions.

Thanks,
Kuphryn
 

KevinMU1

Senior member
Sep 23, 2001
673
0
0
When you specify a size for recv, that's the maximum it will take from the card buffers. For example, if you try to recv 1024 bytes, but only 512 bytes are waiting, you will pull out those 512 bytes and the program will continue.

Further, if you want to send something larger than 2^32 bytes, you will have other issues. Don't let that limitation stop you.

Does that help??
 

kuphryn

Senior member
Jan 7, 2001
400
0
0
Thanks.

2^32 bytes?

I have always thought that a "bytes" means one character i.e. (a, b c, e, c) = 5 bytes.

Kuphryn
 

KevinMU1

Senior member
Sep 23, 2001
673
0
0
bytes does mean one character.

What I was getting at is that you suggested sending four bytes indicating the size of the data to be received. Four bytes would be 2^32 (binary base, 8 bits to the byte), so that means you could say "I want to send 512 MB" (max). My point was, if you need to send 512 megs at once, you have other issues to worry about. :)

Does that make more sense? I would be sure you have a good handle on bits, bytes & data sizes before getting involved in sends & recvs, because if you misalign the sends and the recvs you may end up with lost data.