Problem with Asynchronous Receive in Sockets
Posted on 2002-07-22
Hi I have a problem with the code I wrote below. I wrote the AsyncCallback to repeat calling the ReceiveData method whenever there is more data to receive. However whenthere is no more data to receive from the client, it doesn't attempt to call the ReceiveData method, instead it just halts and wait for more incoming data. Does anyone know what is wrong with my code or if there is a better solution in making sure I have read all the data from the client.
public void ReceiveData(IAsyncResult ar)
int read = aSocket.EndReceive(ar);
if (read > 0)
IAsyncResult ias = temp.BeginReceive(aBuffer,0,aBuffer.Length,0,new AsyncCallback(ReceiveData),so);