TCP Concurrent LAB
TCP Concurrent LAB
Central Punjab
(Faculty of Information
Technology)
Lab 4
Socket Programming:
TCP Client Server Communication
(TCP Concurrent Server)
Lab Manual 04
Objectives
TCP concurrent server
Understanding the fork() call
TCP concurrent server and client communication
Reference Material
Why fork()?
By using fork(), the server can continue listening for new client connections while
each client is handled by its own child process.
In this process:
Close New Descriptor: The parent process (original server) closes the new
socket descriptor for the client, as it's not directly communicating.
Close Old Descriptor: The child process (created by fork()) closes the old
socket descriptor, as it only needs to communicate with its specific client.
1. Setup socket: The server creates a socket to listen for client connections.
2. Bind and listen: The server binds the socket to an IP address and port, then
listens for incoming connections.
3. Accept and fork: When a client connects, the server accepts the connection
and then uses fork() to create a child process for that client.
4. Process client request: The child process takes care of the client’s request
while the main server continues to listen for other clients.
5. Close connection: When the client is done, the child process closes the
connection and exits.
Flow diagram for TCP Concurrent Server & Client communication
Lab Tasks
Task 1. Your task is to create two client processes and show that both the clients are
communicating with the TCP concurrent server at the same time and server is
responding to both of them accordingly.
[10 Marks]
For example
Server side:
Messages:
Client with Port 1234: Hello Server
Client with Port 1235: Hello Server
Client side:
Client with Port 1234
Message:
Server with Port 8080: Hello Client
Task 2. Your task is to modify the client program to accept user input and show on the server
side.
[10 Marks]
Task 3. Your task is to modify the server program to log information about each client
connection, saved in a file named detailed_server_log.txt.
[10 Marks]