In .NET there is the DataAvailable property in the network stream and the Available property in the tcp client.
However silverlight lacks those.
Should I send a header with the lenght of the message? I’d rather not waste network resources.
Is there any other way?
In .NET there is the DataAvailable property in the network stream and the Available
Share
You are micro-optimizing. Why do you think that another 4 bytes would affect the performance?
In other words: Use a length header.
Update
I saw your comment on the other answer. You are using
BeginReadin the wrong way. It will never block or wait until the entire buffer have been filled.You should declare a buffer which can receive your entire message. The return value from
EndReadwill report the number of bytes received.You should also know that TCP is stream based. There is no guarantees that your entire JSON message will be received at once (or that only your first message is received). Therefore you must have some sort of way to know when a message is complete.
And I say it again: A length header will hardly affect the performance.