In Lab Assignment 4

Implementation of a Concurrent Server Using poll()

In the last lab, you have created a concurrent server using fork(). Similarly, you can create a concurrent server using threads. Handling multiple processes/ threads is not an easy task. specially the message passing among processes/threads. In this lab you will write a concurrent TCP server using poll(). poll() actually checks for events on multiple sockets simultaneously and so no need for fork/ thread.

Program Specification: The server will chose a random integer number between 1-100, and wait for the clients to send their guesses. Your server code should be able to run for different number of clients. (Your code can prompt the user to specify the number of clients or you can hard-code the value.) As all clients send their guesses, the server finds out which one of the clients' guesses is -closest- to its own number. Finally, the server sends messages to each of the clients: a congratulations message to the winner client, and to other clients, a phrase indicating that they lost the competition.

Hints:

struct pollfd ufds[clientTotal+1];

 

for(i=0;i<=clientTotal;i++){

            ufds[i].fd = -1;

            ufds[i].events = POLLIN; // check for normal data

      }

      ufds[0].fd = servSock;  //index zero holds server socket descriptor, all other indices hold client sockets

   ufds[0].events = POLLIN;

     Below are some links that might be useful: