|
-
February 23rd, 2006, 05:27 AM
#1
non blocking accept help
Hi !
I don't understand "create non blocking accept".
Can anybody help me with sample code.Thanks!
-
February 23rd, 2006, 05:37 AM
#2
Re: non blocking accept help
There was a similar discussion on non-blocking accept call here , hope it helps
-
February 23rd, 2006, 06:47 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|