M
Manish
Hi !
We are facing a problem ,of not able to recognize that a socket has been
closed from the client .But we observed the socket behaviour under this
situation i.e. "1. Conn.EndReceive(result) , is returning number of read byte
=0", "2. when we check socket status ,it is found True", "3. Evenif the
socket is closed by the client (Close Wait State as shown by "netstate" ) if
we call socket send or receive function that don't raise any exception",
Q1. How to recognize that client has closed the socked ?
Our application Code snap is given below for your reference
Q2. When socked has been closed by the client but socke status is tru ,why ?
//*******************************************//
TCPConnInboundAsync c = (TCPConnInboundAsync)result.AsyncState;
try
{
int num_read = Conn.EndReceive(result);
bytesReaded += num_read;
if ((num_read < bytesToRead && bytesToRead != Buffer.Length))
{
currReadingOffset += num_read;
bytesToRead -= num_read;
lastBeginReceive = DateTime.Now;
Conn.BeginReceive(Buffer, currReadingOffset,
bytesToRead, readSocketFlags, ReadComplete, c);
}
else
{
objTimer.Enabled = false;
readCallback.Invoke(result);
}
}
catch(Exception err)
{
objTimer.Enabled = false;
readException = err;
readCallback.Invoke(result);
}
We are facing a problem ,of not able to recognize that a socket has been
closed from the client .But we observed the socket behaviour under this
situation i.e. "1. Conn.EndReceive(result) , is returning number of read byte
=0", "2. when we check socket status ,it is found True", "3. Evenif the
socket is closed by the client (Close Wait State as shown by "netstate" ) if
we call socket send or receive function that don't raise any exception",
Q1. How to recognize that client has closed the socked ?
Our application Code snap is given below for your reference
Q2. When socked has been closed by the client but socke status is tru ,why ?
//*******************************************//
TCPConnInboundAsync c = (TCPConnInboundAsync)result.AsyncState;
try
{
int num_read = Conn.EndReceive(result);
bytesReaded += num_read;
if ((num_read < bytesToRead && bytesToRead != Buffer.Length))
{
currReadingOffset += num_read;
bytesToRead -= num_read;
lastBeginReceive = DateTime.Now;
Conn.BeginReceive(Buffer, currReadingOffset,
bytesToRead, readSocketFlags, ReadComplete, c);
}
else
{
objTimer.Enabled = false;
readCallback.Invoke(result);
}
}
catch(Exception err)
{
objTimer.Enabled = false;
readException = err;
readCallback.Invoke(result);
}