E
EmeraldShield
Hi all. I have been digging around trying to find an answer to a few
questions that are bugging me. I am hoping someone here can help.
1 - If you start an Async IO (BeginAccept) and the client hangs up what
happens? The docs really don't tell you one way or the other. In my local
testing many of the sockets are never getting released for some reason. I
am not seeing my delegate called. I used an Interlock increment on each
begin and a decrement on each delegate to track it and sometimes they come
through, and sometimes they don't. Very odd. What is the correct behavior?
2 - Why does the .Connected property not update? I have read the docs and
tried lots of tests. It still does not appear to work.
try
{
// Attempt to ensure we are still connected...
byte[] temp = { 0x00 };
// I tried blocking and non-blocking didn't make a difference
sp.Client.Blocking = false;
// This is the MS recommended way. It ALWAYS returns 0 for me and
connected is not updated.
int res = sp.Client.Send(temp, 0, 0);
// I added this as an additional test and the same thing happens.
Always get back 0.
res = sp.Client.Receive(temp, 0, SocketFlags.None);
// If we get here we are still connected and alive...
}
catch( SocketException e )
{
if( e.NativeErrorCode.Equals(10035) )
{
// Still connected - the call would black
}
else
{
// We are disconnected
TimeoutOccured(ref sp);
return (false);
}
}
This app is a socket server that has remote clients connect. I can manually
telnet to the app, watch it start a read, and then kill the telnet app. I
know the socket is gone. I look in the process list and telnet is gone.
But the reads and sends still report it is valid, and connected still
reports true.
I do this test above in my routine prior to calling the beginreceive (I
figure there is no use beginning a receive if the client hung up), and
before sending data. Doesn't seem to make a difference.
What am I doing wrong?
questions that are bugging me. I am hoping someone here can help.
1 - If you start an Async IO (BeginAccept) and the client hangs up what
happens? The docs really don't tell you one way or the other. In my local
testing many of the sockets are never getting released for some reason. I
am not seeing my delegate called. I used an Interlock increment on each
begin and a decrement on each delegate to track it and sometimes they come
through, and sometimes they don't. Very odd. What is the correct behavior?
2 - Why does the .Connected property not update? I have read the docs and
tried lots of tests. It still does not appear to work.
try
{
// Attempt to ensure we are still connected...
byte[] temp = { 0x00 };
// I tried blocking and non-blocking didn't make a difference
sp.Client.Blocking = false;
// This is the MS recommended way. It ALWAYS returns 0 for me and
connected is not updated.
int res = sp.Client.Send(temp, 0, 0);
// I added this as an additional test and the same thing happens.
Always get back 0.
res = sp.Client.Receive(temp, 0, SocketFlags.None);
// If we get here we are still connected and alive...
}
catch( SocketException e )
{
if( e.NativeErrorCode.Equals(10035) )
{
// Still connected - the call would black
}
else
{
// We are disconnected
TimeoutOccured(ref sp);
return (false);
}
}
This app is a socket server that has remote clients connect. I can manually
telnet to the app, watch it start a read, and then kill the telnet app. I
know the socket is gone. I look in the process list and telnet is gone.
But the reads and sends still report it is valid, and connected still
reports true.
I do this test above in my routine prior to calling the beginreceive (I
figure there is no use beginning a receive if the client hung up), and
before sending data. Doesn't seem to make a difference.
What am I doing wrong?