CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2002
    Posts
    7

    Getting Socket Events

    Hi,
    I have a server/client program that uses winsock (im not using the CSocket class). Is it possible to have a function called when data is recieved by the socket? Thanks

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    If you are talking about any kind of event that will occur then the answer is no - at least to my knowledge. and depending on the operating system. In Windows you can work with 'WSA...' events but they are not available on other operating systems...

    However you can use the 'select()' function to determine when more data arrives...
    Code:
    int     iRC         = 0;
    timeval SendTimeout;
    
    // Set timeout
    SendTimeout.tv_sec  = 0;
    SendTimeout.tv_usec = 250000;              // 250 ms
    
    fd_set fds;
    
    FD_ZERO(&fds);
    FD_SET(Socket, &fds);
    
    iRC = select(0, &fds, NULL, NULL, &SendReceiveTimeout);
    
    if(!iRC)
      // Timeout occured
    else if(iRC < 0)
      // Error -> call 'WSAGetLastError()'
    else
      // Data arrives
    Based on this you can implement some kind of notification on your own...
    Last edited by Andreas Masur; September 21st, 2002 at 03:47 PM.

  3. #3
    Join Date
    Feb 2002
    Posts
    5,757
    Yes. You could call a function to receive data. Receiving data has nothing to do with your software design. Heck, you could call a function in another class to receive data. You just have to pass a handle of the socket to the function.

    What I/O model are you using?

    Kuphryn

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured