There are no examples for asynchronous sockets receiving byte data. I can't tell how to identify when such a call has completed.
Within the socket documentation there is a AsyncReceiveBytesN method, but the only way to know how many bytes to pass is to know what the server is sending. For my synchronous calls thus far I have used ReceiveCount easily enough.
But with an asynchronous receive, how do I call ReceiveCount without blocking the thread? And when can I call it? It obviously won't be ready when initiating the asynchronous process, but the the process is initiated by socket.AsyncReceiveBytesN()
It seems to me that socket.AsyncReceiveBytesN() cannot be used with a non-constant value for N, but in my server the data is compressed before sending, and therefor the length is not known in advance.
All I can think to do is have the asynchronous method call a different function on the server that will send a string instead that is marked with "-EOM-", but that would counter my efforts to reduce the size with compression...
asked Jan 14 '14 at 13:24
Yes, you could send the byte count in a string. To minimize the size of the string, you could use hex representation of the number, and with the end marked by a single char, such as "." that cannot possibly be a hex digit. For example, to send 500, you would send "1F4."
answered Jan 17 '14 at 13:41