OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Accepting a Connection

The code below, a non-blocking socket is created on a server.

This socket is bound, starts asynchronous notification, and then starts listening. Some time later, Winsock posts an accept notification, and this causes the listening socket's DoAcceptNotification() function to be called. At this point, the listening socket's Accept() function can be called to complete the acceptance.

Note that the tempSocket doesn't get initialized to have any address; it will get set by the Accept() call.

This example does not use any error checking and reporting. Creating and Connecting a Stream Server and Client shows a similiar sequence of operations.

TStreamSocket
tempListeningSocket(TINetSocketAddress(htons(47), INADDR_ANY);
TStreamSocket tempSocket;
tempListeningStreamSocket.StartAcceptNotification();
.../*Wait until tempListeningStreamSocket.DoAcceptNotification() gets called*/
tempListeningStreamSocket.Accept(tempSocket);
tempSocket.StartRegularNotification();
/*Converts socket to non-blocking*/
//If you are now going to hand off 'tempSocket' to some other class to
// copy it, you may want to call SetSaveSocketOnDelete() on tempSocket,
// because tempSocket defaults to calling closesocket() when it goes out of scope.