+ Reply to Thread
Results 1 to 2 of 2

Thread: How to test whether data is available or not on the socket?

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    29

    How to test whether data is available or not on the socket?

    I want to test whether any data available or not on the given socket.

    How can I do this?

    I am using TCP/IP for my application using winsock socket library.

  2. #2
    Use 'select' method with fd_set for receive data like below:

    Code:
    void IsDataAvailable(SOCKET hSocket)
    {
          fd_set fdset ; 
          FD_ZERO(&fdset) ;
          FD_SET(hSocket, &fdset) ;
          
          if (select(hSocket+1, &fdset, NULL, NULL, NULL) >= 0)
          {
              if (FD_ISSET(hSocket, &fdset))
              {
                    res = recv(....)
               }
          }
    }
    Please note that above code is more like a pseudo code.

    thanks.
    Last edited by Harry; 09-08-2012 at 05:20 AM.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts