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

    non blocking accept help

    Hi !
    I don't understand "create non blocking accept".
    Can anybody help me with sample code.Thanks!

  2. #2
    Join Date
    May 2005
    Posts
    399

    Re: non blocking accept help

    There was a similar discussion on non-blocking accept call here , hope it helps

  3. #3
    Join Date
    Jan 2006
    Posts
    47

    Re: non blocking accept help

    If you wish to accept connections on a non-blocking socket you can use WSAAsyncSelect().

    WSAAsyncSelect() will deliver messages to your window telling you when certain events occur. One of these events you can choose to be informed of is FD_ACCEPT, meaning an incoming connection is ready to be accepted. One could do so like this (simplified):

    Code:
    gsckListen = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    WSAAsyncSelect(gsckListen, ghWnd, MY_EVENT, FD_ACCEPT);
    bind(gsckListen, (sockaddr*)&inConnect, sizeof(inConnect));
    listen(gsckListen, 1);
    Firstly the socket is created. Next, we request that a message called "MY_EVENT" is sent to our window when the socket gsckListen has a connection ready to be accepted with accept(). We then start listening and wait for the event to be sent to our window. In your WindowProc you then handle the MY_EVENT message like so:

    Code:
    BOOL __stdcall WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
      switch (uMsg)
      {
      case MY_EVENT: //accept connection
        gsckConnection = accept(gsckListen, (struct sockaddr*)&inConnect, &iFromLen);
        closesocket(gsckListen); //connection has been accepted; stop listening
    
        break;
      }
    
      ...
    
    }
    You can read more about the use of WSAAsyncSelect() here.

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