Overlap: AcceptEx and Overlapped I/O

Click to open or copy the files for the Overlap sample.

This TCP sample demonstrates the use of AcceptEx and overlapped I/O to multiplex different client connections in a single-threaded Win32 application.

AcceptEx is a Microsoft-specific extension to Windows Sockets. It is not part of the Windows Sockets specification. If you use this function, you will limit your application to implementations of Windows Sockets that support AcceptEx — some implementations do not.

The server uses AcceptEx to handle a number of asynchronous connection requests effectively. When a connection is received, it is added to an array of handles being monitored in a wait function. The server multiplexes between the listening socket and the various client connections.

When a connection is first established, the server queues an overlapped ReadFile operation on the socket. On subsequent notification that this operation has completed, the server queues a WriteFile. Thus, the server alternately reads and writes the socket until the client closes the connection.

Building SDK Samples

This sample uses the following keywords:

acceptex; atoi; bind; closesocket; createevent; dowait; exit; exitprocess; fprintf; getlasterror; getoverlappedresult; getprocessheap; handleevent; heapalloc; heapfree; htons; listen; printf; readfile; socket; switch; tolower; usage; waitformultipleobjects; writefile; wsacleanup; wsagetlasterror; wsastartup; xfree; xmalloc