This project implements a server-client system using socket programming. The server is a math calculator, which responds with calculated result of expression requested by client.
There are three different type implementations of server:
server1.c
is a single process server that can handle only one client at a time. If another client tries to chat with the server while one client session is going on the second client will receive an error message like "line busy!"server2.c
is a multi-process server that forks a process whenever it receives a new client request. Multiple clients will be able to chat with the server concurrently.server3.c
is a single process (single-threaded) server that uses select system call to handle multiple clients concurrently.
cd
to project directory- Compile both server and client program using the following commands
gcc server.c -o server
gcc client.c -c client
- Run the server's executable file using
./server <port_num_to_run_on>
- Run the client's executable file using
./client <port_num_to_connect>
- Both client and server will print a message if the server accepts client's request for connection
Note: replace 'server' with 'server1', 'server2' or 'server3' to run different types of server
As we can see we can connect to only one client at a time, trying to connect second client throws line busy! error.
As we can see, two different processes (process ids are shown while shutting down) were created to handle two different clients
There was only one server, which is used select() system call to handle multiple clients. The clients are connected to different sockets with the server.