Im having a problem with receiving responses from a server Asynchronously ,
can some one please take a look & let me know what might be wrong. The End
Recieve seems to block & not return a value. Below is the code it never goes
ino the else part so I cannot set the ManualResetEven t.
private void OnDataReceived( IAsyncResult asyn)
{
try
{
// Retrieve the state object and the client socket
// from the asynchronous state object.
StateObject state = (StateObject) asyn.AsyncState ;
Socket client = state.workSocke t;
// Read data from the remote device.
int bytesRead = client.EndRecei ve(asyn);
if (bytesRead > 0)
{
// There might be more data, so store the data received so far.
state.sb.Append (Encoding.ASCII .GetString(stat e.buffer,0,byte sRead));
// Get the rest of the data.
client.BeginRec eive(state.buff er,0,StateObjec t.BufferSize,0, new
AsyncCallback OnDataReceived) , state);
}
else
{
// Signal that all bytes have been received.
receiveDone.Set ();
}
}
catch (ObjectDisposed Exception)
{
//MessageBox.Show (e.ToString());
}
}
--
Nikhil Sarathi
can some one please take a look & let me know what might be wrong. The End
Recieve seems to block & not return a value. Below is the code it never goes
ino the else part so I cannot set the ManualResetEven t.
private void OnDataReceived( IAsyncResult asyn)
{
try
{
// Retrieve the state object and the client socket
// from the asynchronous state object.
StateObject state = (StateObject) asyn.AsyncState ;
Socket client = state.workSocke t;
// Read data from the remote device.
int bytesRead = client.EndRecei ve(asyn);
if (bytesRead > 0)
{
// There might be more data, so store the data received so far.
state.sb.Append (Encoding.ASCII .GetString(stat e.buffer,0,byte sRead));
// Get the rest of the data.
client.BeginRec eive(state.buff er,0,StateObjec t.BufferSize,0, new
AsyncCallback OnDataReceived) , state);
}
else
{
// Signal that all bytes have been received.
receiveDone.Set ();
}
}
catch (ObjectDisposed Exception)
{
//MessageBox.Show (e.ToString());
}
}
--
Nikhil Sarathi