Is the socket connected?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • emibt08
    New Member
    • Oct 2008
    • 25

    Is the socket connected?

    Hi. I have an array of sockets in my application and i need to know which sockets are connected and which ones aren't. In order to do that i check if the socket equals INVALID_SOCKET or NULL, but i don't know how efficient that is.
    I wondered how can i know if some of the connected sockets loses the connection from the other side for any reason. Something like the events in the CAsyncSocket, or probably some function that can check just that, if the socket is connected or not. I know i can send data to the other side and check for error, but i wouldn't go for it if there's a cleaner way.
    My application is MFC dialog application and i use blocking raw SOCKET's.

    Thanks in advance
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    You can look for the select() system call and its examples....
    I'm Linux user and hoping that this sys call should be available on windows also...

    Regards,
    Ash

    Comment

    • gpraghuram
      Recognized Expert Top Contributor
      • Mar 2007
      • 1275

      #3
      WIN_SOCK provieds the select call functionality and can be used the same way as select in Linux

      raghu

      Comment

      Working...