Question

I use CAsyncSocket with events, for example I overwrite OnReceive().

However, I am not completely clear at which "level" this should be implemented. For example, the other end could send data byte-by-byte; OnReceive would then be called after every byte, right?

So if I am in OnReceive and use Receive ...and not all my data I expect is received, what shall I do? Buffer the stuff and return and wait for the next OnReceive?

But this seems very high-level: I would need a state machine and different buffers with high-protocol knowledge to handle this.

Wouldn't it just be possible to say: "Notify me when at least 4 bytes are received"? Then I would not need to deal with the low-level stuff and once the notification is here I just read exactly 4 bytes (even if more are already available).

Was it helpful?

Solution

There is no way to control how many bytes a call to Receive will give you. So you must buffer the stuff and wait for another call to OnReceive.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top