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

مشاهدة النسخة كاملة : Receiving Data Asynchronously on Socket Class



C# Programming
10-04-2011, 10:24 AM
I'm using BeginReceive to receive data on a Socket.

Sometimes the receive completes synchronously, as indicated by the IAsyncResult.CompletedSynchronously member.

The problem is: I don't know how to retrieve the number of bytes received in this case, because usually it is the EndReceive function that returns this information. But you're not allowed to call EndReceive when it completes synchronously, because it will throw an InvalidOperation exception.

Does anyone know how to retrieve the number of bytes received when the receive completes synchronously?



The difficult we do right away...
...the impossible takes slightly longer.