Ftpalgo
Ftpalgo
Aim: To develop a concurrent file server which will provide the file requested by the
client if it exists. If not, the server sends appropriate messages to the client. Server
sends its process ID (PID) to clients for display along with the file or the message.
Description:
The file server creates listening sockets on two ports that have consecutive port
numbers. One is the listening socket for control connection and the other is the
listening socket for data connection. These sockets have descriptors listen_control
and listen_data respectively. The client creates a socket and connects to the server
using TCP connection. The client socket descriptor is stored in sock_ctrl. The server
creates a connection socket when the client makes a TCP connection with the server.
This connection socket is stored in sock_ctrl. This connection is for control
information to pass between client and server. Next, the server forks a child process.
Since the child is a perfect image of its parent, the child process will also have
descriptors listen_control, listen_data and sock_ctrl. The control connection will also
be duplicated between the client and the child process. The child process closes its
listening socket for control connection, i.e; listen_control. The parent server process
closes its connection socket for the control connection i.e; sock_ctrl. The client now
makes a TCP connection with the server for transferring data stored in sock_data.
The connection socket for the data connection is stored in sock_data in the server
child process.
Algorithm
Client
1. Create the client TCP control connection to a port (port_num) of the server
with the client socket descriptor sock_ctrl.
2. `while(1)
{
1. Create client socket descriptor sock_data for the data connection with
server on another port (portnum + 1). For each file transfer a new data
connection is required.
4. If command == “close”
close sock_data and sock_ctrl
break
5. Enter the filename using the keyboard
8. read data using sock_data (file contents) from the server and write to the file
Server
2. Create listening socket for the control connection on port (port_num) and store it in
listen_control.
3. Create a listening socket for the data connection on port (port_num +1) and store it in
listen_data
4. while (1)
1. accepts the client control connection and returns the connect socket descriptor
sock_ctrl
1. if(childprocess)
while(1)
if command
==
“close
break
else
read the filename from the client using control connection open the file
if (no file)
form a string “@FILE NOT FOUND PROCESS ID = getprocess id” and store it in
variable buffer
file_present = 0;
accept the data connection and return the socket descriptor sock_data
if(file_present)
else
file_present = 1;
close sock_data
process exits
close( sock_ctrl)
}
5. close(listen_control);
close(listen_data);