TH8-9 Server Design: Iterative Server Algorithms

Iterative TCP (Connection Oriented) Server Algorithm
socket: allocate a socket
bind: bind the socket to the service port number (passed in sockaddr_in structure) for the service being offered
listen: place the socket into passive mode and set max. number of simultaneous connections i.e. make it ready for use by a server
accept: accept the next incoming connection request from the socket and obtain a new socket for the connection
read: read incoming data from the connection and formulate the response
write: send outgoing data across the connection
close: when finished with a particular client, close the connection, de-allocate socket descriptor and return to listen whether another connection will be requested.

Characteristics: a SINGLE socket per SINGLE connection.
Binding in the service port number (well known part)
Hosts that have only a single address can use their IP straight, hosts that have several IP addresses (e.g. routers) can use a special address INADDR_ANY (a predefined constant) as a special wild card address.
Placing the socket into passive mode
The socket must be placed into passive (listening) mode in connection-oriented servers.
Accepting connections and using them
The accept() call returns the descriptor of the NEW socket to be used for a new connection Accept() is a routine with “blocking” feature i.e. it stops the process and waits but does NOT waste any system resources during this block. When Connect() request arrives then it “wakes up” handles the request and the process can continue.

Iterative UDP (Connectionless) Server Algorithm

Socket: allocate a socket

Bind: bind the socket to the service port number (passed in sockaddr_in structure) for the service being offered. The server’s socket remains UNCONNECTED and can accept incoming datagrams from ANY client.

Read: read incoming data from the connection and formulate the response.

Write: send outgoing data across the connection

Close: when the server is to get down

Characteristics: a SINGLE socket per MANY connection
No accept() call
The server can accept requests from many clients through a SINGLE socket (created by bind) thus the accept() which links the server with a single client can NOT be used.
Forming a reply address in a Connectionless server
The server uses a system call recvfrom() that receives the client’s address along with the next datagram that arrives.
The server is to, explicitly, place the client’s IP address into the sockaddr_in structure and use a sendto() system call to transmit both.

Welcome to Kaizenlog.com If you're new here, you may want to subscribe to my RSS feed , Twitter You can contact us by using the contact form or submitting a comment. You can also share this post with your friends by clicking on the 'ShareThis' button above. Thanks for visiting!



Print This Post Print This Post





  • Related Posts



  • Leave a Reply