News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Question about this SDK sockets code

Started by Rainstorm, December 27, 2008, 06:04:10 AM

Previous topic - Next topic

Rainstorm

hi,.. in the SDK there is this sockets code associated with the 'accept' function
i can't figure out the line    m_socket = AcceptSocket
why is the listening socket descriptor being set to the newsocket descriptor ?
shouldn't the listening socket be left on its own, to listen for new connections maybe ?

thankyou.
printf( "Waiting for a client to connect...\n" );
    while (1) {
        AcceptSocket = SOCKET_ERROR;
        while ( AcceptSocket == SOCKET_ERROR ) {
            AcceptSocket = accept( m_socket, NULL, NULL );
        }
        printf( "Client Connected.\n");
        m_socket = AcceptSocket;
        break;
    }

Rainstorm

think i figured it out, its because later on in the full code they use the same listening socket (m_socket) as the new socket to send & receive data.  :P - just the above snippet (in the previous post) was on the 'accepting a connection' page though .
if there is some other reason.. please let me know

t  y
----

Tedd

The code is badly written - if you're trying to learn from it, get a better example.

And you're right, you should keep the listening socket as is (destroy it explicitly if you no longer need it) - 'accept' returns a NEW socket for the received connection, and the listening socket remains as it was.
No snowflake in an avalanche feels responsible.