Click here to Skip to main content
15,746,883 members
Please Sign up or sign in to vote.
2.60/5 (3 votes)
See more:

I have created socket application in which server is sending 1024 bytes data to client and client is able to read only 256 bytes at once.

here i am loosing some data ,

How can i make sure that i should receive 1024 bytes.

Updated 26-Dec-13 22:31pm
Sergey Alexandrovich Kryukov 27-Dec-13 2:40am    
How needs to clarify what? Absurd.

1 solution

It is more than likely that you are expecting all the data to appear in a single receive operation. That is not how TCP/IP works, it is not like reading a block of data from disk. TCP/IP has to break your block of data down into smaller components, which means that not all the data will be received at the same time. You need to repeat the receive operation until you have the complete 1024 bytes in your buffer. Google for "socket sample C++" and you will get some samples that show how it is done.
Share this answer

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