I am using the BeginReceive() and EndReceive() method for async IO using Sockets in .NET. The client sends continuous packets of data and calling EndReceive() returns the number of bytes read.
The problem is that the client is sending packets of data but data length is ZERO. It found this by analyzing the traffic in WireShark. When the length of data is Zero, the EndReceive() call just blocks there.
Is there a way to identify the ZERO length data without actually blocking on EndReceive()?
Also, the ReceiveTimeout property does not seem to work on Async methods.
Sample Source Code:
// This method runs on a separate thread
private void ProcessRequest()
{
BeginReceive(OnClientReceive);
// Do some work here in a loop
}
// Callback method
private void OnClientReceive(IAsyncResult result)
{
int receivedCount = socket.EndReceive(result); // this one blocks
// Do some work here
// Again start listening for data
BeginReceive(OnClientReceive);
}