System.Net.Socket.Connected --- eek
-
I am porting a VB6 winsock.ocx based library to a .Net Sockets implementation, and I am not the most savvy sockets programmer. The architecture of the communication system was designed long before I got here; so changing the overall design is not an option. Moreover, this system has a low frequency of tcp traffic, so the
Socket.Connected
will almost always be out-of-date. The fundamental issue is the connected property of the socket. It does not seem to be funcitonal; however, I have found others that have had similar issues http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.connected.aspx[^] When I stepping-through the code in the debugger, unplug the network at the right moment, and view the sock object with the quick watcher, it shows me the value ofsock.Connected
has changed to false as expected. However, while running the code below, in debug mode but not stepping-through, the behavior ofsock.Connected
is different (when I unplug the wire, it does not update to false). Thoughts?private bool isConnected(){
bool rVal = false;
//an alternate way to refresh the connected status of the sock.
try
{
bool blcking = sock.Blocking;
try
{
byte[] junk = new byte[2];
sock.Blocking = false;
sock.Send(junk, 1, 0, SocketFlags.None);
rVal = sock.Connected;
}
finally
{
sock.Blocking = blcking;
}} catch (SocketException e) { rVal = e.SocketErrorCode == SocketError.WouldBlock; } return rVal;
}
You can only be young once. But you can always be immature. - Dave Barry
-
I am porting a VB6 winsock.ocx based library to a .Net Sockets implementation, and I am not the most savvy sockets programmer. The architecture of the communication system was designed long before I got here; so changing the overall design is not an option. Moreover, this system has a low frequency of tcp traffic, so the
Socket.Connected
will almost always be out-of-date. The fundamental issue is the connected property of the socket. It does not seem to be funcitonal; however, I have found others that have had similar issues http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.connected.aspx[^] When I stepping-through the code in the debugger, unplug the network at the right moment, and view the sock object with the quick watcher, it shows me the value ofsock.Connected
has changed to false as expected. However, while running the code below, in debug mode but not stepping-through, the behavior ofsock.Connected
is different (when I unplug the wire, it does not update to false). Thoughts?private bool isConnected(){
bool rVal = false;
//an alternate way to refresh the connected status of the sock.
try
{
bool blcking = sock.Blocking;
try
{
byte[] junk = new byte[2];
sock.Blocking = false;
sock.Send(junk, 1, 0, SocketFlags.None);
rVal = sock.Connected;
}
finally
{
sock.Blocking = blcking;
}} catch (SocketException e) { rVal = e.SocketErrorCode == SocketError.WouldBlock; } return rVal;
}
You can only be young once. But you can always be immature. - Dave Barry
Hi, I don´t know that i think, but do you know about Asynchronous connections? If not read about it! Maybe because you are not using that your sockets blocks. Check out the way you managed your threads maybe because you are invoking a wrong thread! :(( Sorry i can´t help you more!
-
Hi, I don´t know that i think, but do you know about Asynchronous connections? If not read about it! Maybe because you are not using that your sockets blocks. Check out the way you managed your threads maybe because you are invoking a wrong thread! :(( Sorry i can´t help you more!
Well - Thanks for your input anyways
You can only be young once. But you can always be immature. - Dave Barry