Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I read that TCP ensures the order of arrival of packets, but does not ensure that they are complete.
I also read that a system to solve this problem would be to first send the packet size and then read up until receiving a full package, but I do not understand how to implement such a system.
Posted

You have to thing about that TCP is like a pipe where data can be transported in. On top of that, you can implement what ever protocol or message system you like.

Say you what to send and receive a file. Then you have to tell the receiver some information about that file you will sent. It can be file name, create date/time and the size of the file.
When the receiver knows about that info, it will know how to interpret the data received.

See how HTTP protocol[^] is built up. Its been used for many years now.
 
Share this answer
 
Comments
Morph King 8-Jun-11 15:08pm    
i need to know how to implement a system that ensure i received full message with async read
Sergey Alexandrovich Kryukov 8-Jun-11 17:18pm    
Avoid async operation as threads are much more robust.
--SA
Sergey Alexandrovich Kryukov 8-Jun-11 17:20pm    
Please see my solution.
--SA
Kim Togo 9-Jun-11 4:11am    
To ensure to receive all data, you call NetworkStream.BeginRead when you are done in the callback method. This tell that you are ready to receive more data. When there is no more data, callback method it not called.
See NetworkStream.EndRead
Sergey Alexandrovich Kryukov 8-Jun-11 17:20pm    
I'll vote 5 for this answer. See also my solution.
--SA
Please see the skeleton design I show in my past solution:
Multple clients from same port Number[^].

—SA
 
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