In Lab assignment 5

Implementation of a Concurrent Server Using Multi-Threading

You already have created concurrent server using fork (multi-processing) and poll (polling a number of sockets simultaneously). In this lab, you have to create a concurrent server using multi-threading.. This is the same program you have created in lab 4, but this time you will use multiple threads instead of polling the sockets.

The program format for the server should be similar to creating concurrent server using fork(). In terms of programming, the benefit of multithreading is that the global variables are shared by all the threads which can be used for communication between/among threads. You can reuse the previous client-code.

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.

Here is a short program to understand how thread works. Compile the code with –pthread option.