Thread: Winsock, Or Winsock2

  1. #1
    Registered User
    Join Date
    Feb 2005

    Winsock, Or Winsock2

    Hello. How do you detect when the remote end of a connection has disconnected? I get alot of timeouts, but that doesnt tell me that ive disconnected absolutely. Any suggestions? Is there anything besides a timeout error that can be used?

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Seattle, WA
    When the program shuts down, have it send a disconnect message...If it doesn't send a message saying it's quitting, you can only tell by timeouts.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."

  3. #3
    Registered User
    Join Date
    Jun 2004

    Upon successful completion, recv() shall return the length of the message in bytes. If no messages are available to be received and the peer has performed an orderly shutdown, recv() shall return 0. Otherwise, -1 shall be returned and errno set to indicate the error.

  4. #4
    Registered User
    Join Date
    May 2005
    If remote end of a connection is in Asynchronous mode, you wud receive FD_CLOSE notification message provided u set it in the call to WSAAsyncselect().

    Hope this helps

  5. #5
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    In a separate "receiver" thread you could simply select() for readability then peek at the incoming message and check if the peek errors out. If it does, the connection was closed.

    See my socket library ( for an example.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Winsock issues
    By tjpanda in forum Windows Programming
    Replies: 3
    Last Post: 12-04-2008, 08:32 AM
  2. winsock vs. winsock2 ?
    By Devil Panther in forum Networking/Device Communication
    Replies: 10
    Last Post: 11-06-2005, 10:38 AM
  3. Winsock Messaging Program
    By Morgul in forum Windows Programming
    Replies: 13
    Last Post: 04-25-2005, 04:00 PM
  4. Where do I initialize Winsock and catch messages for it?
    By Lithorien in forum Windows Programming
    Replies: 10
    Last Post: 12-30-2004, 12:11 PM
  5. winsock
    By pode in forum Networking/Device Communication
    Replies: 2
    Last Post: 09-26-2003, 12:45 AM