When we send a large amount of data to the client,its Rec开发者_开发百科eiveAsync event is being called more than one time and in each time we get a few piece of the packet.
What shall we do to get C# Silverlight Tcp Packet in one piece and through one event? Thank you in advance.You can't. The very nature of TCP is that data gets broken up into packets. Keep receiving data until you've got the whole message (whatever that will be). Some options for this:
- First send the size of the message before the message itself.
- Close the connection when the message has been sent (so the client can basically read until the connection is closed)
- Add a delimiter to indicate the end of the message
I generally dislike the final option, as it means "understanding" the message as you're reading it, which can be tricky - and may mean you need to add escape sequences etc if your delimiter can naturally occur within the message.
精彩评论