select help

This is a discussion on select help within the Networking/Device Communication forums, part of the General Programming Boards category; Hi. How can i find out when a client closed a socket, using select....

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    5

    select help

    Hi.
    How can i find out when a client closed a socket, using select.
    Last edited by asdffa; 11-18-2006 at 01:07 PM.

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    I believe (not at home, so I can't confirm) that you place the socket you want to check for being closed in the set to be checked for reading. (As if you wanted to check if data had arrived on the socket.) Then, in your call to recv(), if the socket has been closed, (and after you've recv()'d any waiting data), it'll return 0 for closed. (And maybe <0 on error, but I'm not sure.)

    See the MSDN page on select() as well as the unix man page. Shouldn't be too hard to whip up an example yourself to test.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    5
    Quote Originally Posted by Cactus_Hugger
    I believe (not at home, so I can't confirm) that you place the socket you want to check for being closed in the set to be checked for reading. (As if you wanted to check if data had arrived on the socket.) Then, in your call to recv(), if the socket has been closed, (and after you've recv()'d any waiting data), it'll return 0 for closed. (And maybe <0 on error, but I'm not sure.)

    See the MSDN page on select() as well as the unix man page. Shouldn't be too hard to whip up an example yourself to test.
    Thanks.
    By the way, another question.
    In a TCP session, i want that the server make 2 consecutive writes, how can i read this in the client.
    If i make 2 read's the second answer is never received by the client.

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    I don't think I can give you an answer with that... we'd need to see some code. Generally, the method you describe works. Common errors including things like not understanding how send()/recv() work, mainly that they are not guarenteed to actually send()/recv() the amount you tell them to. (See the man pages)
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 08:26 PM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 05:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 05:42 PM

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