CN Labsheet 5
CN Labsheet 5
1. HTTP proxy set-up (Work in a team of two. First member will install proxy server and other will
connect from a client)
i. Install tinyproxy in Ubuntu system using sudo apt-get update
sudo apt-get install tinyproxy
ii. Open tinyproxy.conf file using vi (In the Terminal: sudo vi /etc/tinyproxy.conf)
iii. Uncomment the line “Allow 172.16.0.0/12” (Refer the figure below). By this, you are allowing
anyone on 172.16.x.x to connect to your machine. Alternatively, you may restrict access to one
or few machines. To allow access to only your client, type the client machine’s IP address (add
the following entry in the file: Allow <<IP of client>>). If you choose to do this, DO NOT
uncomment the entry which was specified above.
iv. Save the file and exit.
v. Now, restart Tinyproxy for the changes to take place. In the terminal:
sudo /etc/init.d/tinyproxy stop
sudo /etc/init.d/tinyproxy start
ii. Now, on your client’s Firefox, connect to www.google.com and capture packets on Wireshark.
▪ Firstly, when you are connected to the proxy, and
▪ Secondly, without being connected to the proxy.
What differences do you observe? When not connected to proxy, can you see the connection being
made with www.google.com?
iii) When connected to the proxy, you can only see the proxy server!! (In this case, 172.26.90.4)
iv. Before you leave, please remove tinyproxy from your machine so that the next lab’s students can have
the opportunity to configure it themselves. sudo apt-get remove tinyproxy
In this labsheet, we will build a simple client-server system, where you use the client to chat with a
dummy server. The protocol between the client and server is as follows.
The server is first started on a known port.
The client program is started (server IP and port are provided on the commandline).
The client connects to the server, and then asks the user for input. The user types his message on
the terminal (e.g., "Hi", "Bye", "How are you"). The user's input is sent to the server via the
connected socket.
The server reads the user's input from the client socket. If the user has typed "Bye" (without the
quotes), the server must reply with "Goodbye". For any other message, the server must reply with
"OK".
The client then reads the reply from the server, and checks that it is accurate (either "OK" or
"Goodbye").
If the user had typed "Bye", and the server replied with a "Goodbye" correctly, the client quits.
Otherwise, the client asks the user for the next message to send to the server.
Do the above for: i) Both TCP and UDP sockets ii) Both localhost and anyother host (for e.g. using your
neighbor’s IP address).
1) Find out the different classes of address families that exist.
2) What can be different values of the field protocol? In what scenarios will these different protocol
values be applicable?
ChatApp:
A simple client server program is blocking. That is the end systems cannot communicate independent of
each other. To do this we need to create separate thread for read and write, wherein one of the thread will
handle the write process and the other (the main process) will handle the read process or vice-versa. Sample
server program is given. Use this code to write the client code.
#include"stdio.h"
#include"stdlib.h"
#include"sys/types.h"
#include"sys/socket.h"
#include"string.h"
#include"netinet/in.h"
#include"pthread.h"
void main() {
struct sockaddr_in addr, cl_addr;
int sockfd, len, ret, newsockfd;
char buffer[BUF_SIZE];
pid_t childpid;
char clientAddr[CLADDR_LEN];
pthread_t rThread;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = PORT;
len = sizeof(cl_addr);
newsockfd = accept(sockfd, (struct sockaddr *) &cl_addr, &len);
if (newsockfd < 0) {
printf("Error accepting connection!\n");
exit(1);
}
close(newsockfd);
close(sockfd);
pthread_exit(NULL);
return;
}
Design a simple chat-based application using client server socket programming using C.
1. The server listens to well-known ports from the client for a chat request.
2. The client must send the first message as “Hello” to start the chat communication.
3. In this any or both the parties should be able to send the message
independent of each other.