Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. System.Net.Socket.Connected --- eek

System.Net.Socket.Connected --- eek

Scheduled Pinned Locked Moved C#
debuggingcsharpcomdesign
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jason McBurney
    wrote on last edited by
    #1

    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 of sock.Connected has changed to false as expected. However, while running the code below, in debug mode but not stepping-through, the behavior of sock.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

    N 1 Reply Last reply
    0
    • J Jason McBurney

      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 of sock.Connected has changed to false as expected. However, while running the code below, in debug mode but not stepping-through, the behavior of sock.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

      N Offline
      N Offline
      nelsonpaixao
      wrote on last edited by
      #2

      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!

      J 1 Reply Last reply
      0
      • N nelsonpaixao

        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!

        J Offline
        J Offline
        Jason McBurney
        wrote on last edited by
        #3

        Well - Thanks for your input anyways

        You can only be young once. But you can always be immature. - Dave Barry

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups