CITS3002 Computer Networks  
prev
next CITS3002 help3002 CITS3002 schedule  

Iterative Servers - managing a single connection

Firstly, consider a iterative server - each connection, or session, with a distinct client is handled until its completion.

Our server process will fully service each client until its completion, and continue to service subsequent clients until told to terminate.

Case 1 - makes subsequent clients wait:

//  Open a socket, listen, bind an address
    ....

    bool keep_going = true;

    while(keep_going) {
        int new_client   = accept(mysocket, ....);

        if(new_client == -1) {
            perror("accept");
            keep_going = false;
        }
        else {
	    extern bool service(int sd);

            keep_going = service(new_client);

	    shutdown(new_client, SHUT_RDWR);
            close(new_client);
        }
    }

    shutdown(mysocket, SHUT_RDWR);
    close(mysocket);

If the time to service each client is lengthy, or of indeterminable duration, new clients may be kept waiting for their initial connection - perhaps being terminated with an error of ECONNREFUSED.


CITS3002 Computer Networks, Lecture 9, Client/server design, p8, 1st May 2024.