aphelix
February 23rd, 2006, 04:27 AM
Hi !
I don't understand "create non blocking accept".
Can anybody help me with sample code.Thanks!
I don't understand "create non blocking accept".
Can anybody help me with sample code.Thanks!
|
Click to See Complete Forum and Search --> : non blocking accept help aphelix February 23rd, 2006, 04:27 AM Hi ! I don't understand "create non blocking accept". Can anybody help me with sample code.Thanks! leojose February 23rd, 2006, 04:37 AM There was a similar discussion on non-blocking accept call here (http://www.codeguru.com/forum/showthread.php?t=315840&highlight=blocking+accept) , hope it helps runesvend February 23rd, 2006, 05:47 AM 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): 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: 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 (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsaasyncselect_2.asp). codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |