Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I create a client server app,But the client did not receive more 5000 bytes.
Please help me.
Posted
Comments
pasztorpisti 18-Jul-13 17:23pm    
In theory in worst case you will receive the 5000 bytes one-by-one with 5000 separate reads. You have to allocate a buffer to receive the data and you have to call recv() in a loop and always append the received small chunk of bytes to the end of your buffer. When the buffer size reaches 5000 you have your data there. If you are luck you can read out 5000 bytes with one recv() call from the recv buffer of the socket object, if you have a bad day you will have to make 5000 recv() calls each of them reading only 1 byte (this is just theory and one of my network stress test cases).

1 solution

There's no guarantee that you'll get all of your data in one packet.

With large packets, the sending application will often break it into chunks, that you'll need to reassemble.
 
Share this answer
 
v2
Comments
Alamgirable 18-Jul-13 14:58pm    
Please give the code example...
JackDingler 18-Jul-13 15:44pm    
Have you tried Google? There are many excellent examples on the web. Far better than anything I have time to write for you.

You're stuck on a very basic problem. You have quite a bit research and education ahead of you.
If you're in school and this is a homework assignment, go back over the material your instructor has provided. Ask questions of your instructor and teacher's aides.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900