المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Client-Server communication



C# Programming
12-02-2009, 01:26 AM
Hi;
I'm trying to create a server whose client-handler gets a tcpclient-object and needs to read data.
My problem is: when using the networkstream.read(byte[], offset, length) method, you cant really tell when the client has stopped sending a block.
I tried using while(length == buffer.length) to check if the buffer has been completely filled, meaning there is still data on the stream, but that does not include the possibility that the client has send exactly the amount of bytes the buffer can hold. Then i tried using the DataAvailable-property of the stream, but how does this work when the clients for example sends two different objects, which both happen to have the same size as my buffer? I would read the first object but there would still be data available on the stream since the second object was send right after the first one.
Could someone please point me in the right direction for receiving a variable amount of data representing a custom class / structure over the internet?
MfG Frank