[Q] EndReceive Asynchron C# Socket

A

Andre

Hi,

I'm implementing an asynchron socket Receiving method and I have a
question about EndReceive.

Read()
{
Socket.BeginReceive(buf,0,buf.Length,0,new
AsyncCallback(ReadCallback),dp);
}

ReadCallback(IAsyncResult asyncRes)
{
...
int bytesRead = Socket.EndReceive(asyncRes);
...
}

My question is now, what happens if I try to receive a datapacket
which is greater than the buffer buf? EndReceive returns when when the
buffer buf is full. Can I call EndReceive again? or should I restart
Read()? But how can I know that there are datas waiting for reading?

Thanks
André Betz
http://www.andrebetz.de
 
I

Ivar

Hi,
EndReceive returns when when the buffer buf is full.
No, it may retrun less bytes than buffer, because of it ALWAYS see hwo much
int bytesRead = Socket.EndReceive recived.
Can I call EndReceive again? or should I restart
No, you must start from BeginRecieve again
Read()? But how can I know that there are datas waiting for reading?
You don't need to know that, BeginRecieve waits data to arrive.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top