Varifying Socket Connection :: Winsock

This is a discussion on Varifying Socket Connection :: Winsock within the Windows Programming forums, part of the Platform Specific Boards category; Hi. I was wonder about the best way to varify if a socket is currently active. In other words, I ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    Varifying Socket Connection :: Winsock

    Hi.

    I was wonder about the best way to varify if a socket is currently active. In other words, I need a way to determine if there is a connect on a socket. This is just for command update UI. Basically, if the socket is active, I enable/disable something. If not, I enable/disble something.

    How about this code?

    // if (mysocket == WSAENOSOCKET)
    // socket is invalid or inactive

    Thanks,
    Kuphryn

  2. #2
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    Try:

    Code:
    if (socket != INVALID_SOCKET)
       // connection is alive, or at least socket exists
    Be sure to set your socket pointer value to INVALID_SOCKET on initialization so that the program doesn't mistake an actual connection for whatever value the pointer referred to at creation time.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Thanks.

    Nish [BusterBoy] posted a different solution using two API functions. Your solution parallel pointer and NULL.

    Here is a link to the solution I mentioned.

    http://www.codeproject.com/script/co...001#xx178001xx

    Kuphryn

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Nice! I looked up INVALID_SOCKET at MSDN. Your technique looks very promising.

    Thanks again,
    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Non-blocking socket connection problem
    By cbalu in forum Linux Programming
    Replies: 25
    Last Post: 06-03-2009, 02:15 AM
  2. reuse a socket connection
    By radeberger in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-18-2009, 11:38 AM
  3. Winsock issues
    By tjpanda in forum Windows Programming
    Replies: 3
    Last Post: 12-04-2008, 07:32 AM
  4. Winsock connection problem
    By Nephiroth in forum C++ Programming
    Replies: 2
    Last Post: 02-07-2006, 06:54 AM
  5. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21