CS 372 Computer Networks: Assignment #3
CS 372 Computer Networks: Assignment #3
CS 372 Computer Networks: Assignment #3
html
CS 372
Computer Networks
Assignment #3
Submitted by:
Ashish Gupta , 98131
Ravi Krishna , 98422
Description
In this assignment , we were told to develop a series of programs based on socket programming using both TCP and UDP protocol.
7 programs were developed in this assignment
http://www.cs.northwestern.edu/~agupta/_projects/networking/TCPClientServer/report.html 1/4
4/2/2018 www.cs.northwestern.edu/~agupta/_projects/networking/TCPClientServer/report.html
In the TCP Echo server , we create a socket and bind to a advertized port number.
After binding , the process listens for incoming connections.
Then an infinite loop is started to process the client requests for connections.
After a connection is requested , it accepts the connection from the client machine and forks a new process.
The new process receives data from the client using recv() function and echoes the same data using the send() function.
Please note that this server is capable of handling multiple clients as it forks a new process for every client trying to connect
to the server.
In the UDP Echo server , we create a socket and bind to a advertized port number.
Then an infinite loop is started to process the client requests for connections.
The process receives data from the client using recvfrom () function and echoes the same data using the sendto() function.
Please note that this server is capable of handles multiple clients automatically as UDP is a datagram based protocol hence
no exclusive connection is required to a client in this case.
We have used the concept of I/O multiplexing for managing both TCP and UDP port in the same server.
fd_set fdvar;
FD_ZERO(&fdvar);
FD_SET(tcp_sfd,&fdvar);
FD_SET(udp_sfd,&fdvar);
int maxpl = max(tcp_sfd,udp_sfd);
cout << "Waiting for a client...\n";
if(select(maxpl+2 ,&fdvar,NULL,NULL,NULL)==-1)
{
perror("error in select");
}
if(FD_ISSET(udp_sfd,&fdvar))
{
// UDP
}
else
{
//TCP
}
struct fd_set can be set to monitor activity on many ports at the same time.
FD_SET(tcp_sfd,&fdvar) sets the appropriate bit in fdvar so that select may monitor tcp_sfd
similarly FD_SET(udp_sfd,&fdvar) sets the appropriate bit in fdvar so that select may monitor
the udp_sfd.
http://www.cs.northwestern.edu/~agupta/_projects/networking/TCPClientServer/report.html 2/4
4/2/2018 www.cs.northwestern.edu/~agupta/_projects/networking/TCPClientServer/report.html
We use select system call to monitor socket fd's for TCP & UDP servers which are
listening to the same port ie. port 3001
In this part of the assignment we have proceeded on the lines of TCP Echo Server / Echo Client.
We create a TCP Server which listens for various TCP Clients trying to connect to the server.
Once a client connects we start a new process which deals with that particular client.
It receives the message from the client and breaks it into various tokes seperated by space.
It then analyses the arguments for "ls" and "cat" command otherwise it returns a default message.
If it receives a "ls" or "cat" command , it executes the command on the system and collects the output in a file on the server side. Then it
reads the file line by line and sends it to the client machine.
In the "cat" part of the program , it transmits 24 lines of the file at one time and then waits for an acknowledgement from the client machine
before proceeding to display the next 24 lines of the file.
The user on the client machine may also transmit "q" to finish the "cat" command in between its execution.
The TCP Server also shows which clients are connecting and also displays what information it gets from the various clients to show how the
server is working.
Output
1. The Server in the TCP Server/Client System generates the following output :
Connected to : 10.20.14.25
Received from 10.20.14.25 : ls
Connected to : 10.20.14.25
Received from 10.20.14.25 : ls
As we can see , it displays which clients have connected to it. It also displays any messages receieved from it. If the client closes down , it
shows that the connection to the respective client has been closed.
2. The Client in the TCP Server/Client System generates the following output :
Connecting to 10.20.14.25
Connected.
http://www.cs.northwestern.edu/~agupta/_projects/networking/TCPClientServer/report.html 3/4
4/2/2018 www.cs.northwestern.edu/~agupta/_projects/networking/TCPClientServer/report.html
10.20.14.25 : ls
TCPClient.cpp
TCPFileClient.cpp
TCPFileServer.cpp
TCPServer.cpp
UDPClient.cpp
UDPDateClient.cpp
UDPServer.cpp
YSOSREHFTFANAEETQVTMXWSLPIQVIZJJUXBLDKTWRTJSXPLPLGCKCWVTEOQMPZVJYZVBLOZDJJVHAIYN
a.out
cs.gif
inet.h
io
iomux.cpp
report.html
tc
tcpc
tcps
temp
tfc
tfs
ts
uc
us
10.20.14.25 : hello
what was that !?
10.20.14.25 :
As we can see , the client display a prompt with the IP number of the server. We can issue commands to the server and get the corresponding
output.
The above server displays what type of protocol a client is using to communicate and displays the messages received.
http://www.cs.northwestern.edu/~agupta/_projects/networking/TCPClientServer/report.html 4/4