Network Programming
Network Programming
➢ Most networking applications are written assuming one side is the client
and the other the server (client to server model or peer to peer model)
➢ The purpose of the application is for the server to provide some defined
service for clients.
➢ We can categorize servers into two classes: iterative or concurrent.
➢ An iterative server iterates through the following steps:
1. Wait for a client request to arrive.
2. Process the client request.
3. Send the response back to the client that sent the request.
4. Go back to step 1.
➢ The problem with an iterative server is when step 2 takes a while. During
this time no other clients are serviced.
➢ A concurrent server performs the following steps.
1. Wait for a client request to arrive.
2. Start a new server to handle this client’s request.
This may involve creating a new process or task, depending on what the underlying
operating system supports. How this step is performed depends on the operating
system. This new server handles this client’s entire request. When complete, this new
server terminates.
3. Go back to step 1.
Dr. Elhossiny Ibrahim 0 4th year: network programming
Client-Server Model
➢ The advantage of a concurrent server is that the server just spawns other
servers to handle the client requests.
➢ Each client has, in essence, its own server.
➢ Assuming the operating system allows multiprogramming, multiple clients
are serviced concurrently.
➢ The reason we categorize servers, and not clients, is because a client
normally can’t tell whether it’s talking to an iterative server or a
concurrent server.
➢ As a general rule:
➢ TCP servers are concurrent.
➢ UDP servers are iterative.
➢ but there are a few exceptions.
➢ Explanation:
• We connect to localhost on port 40674 (the port on which our server runs) and
lastly, we receive data from the server and close the connection.
• Now save this file as client.py and run it from the terminal after starting the
server script.