Description
Objective: The objective of this assignment is to understand the functionalities of the select() system call through a network application – a Peer-to-Peer Chat Application. Problem Description: The objective of this assignment is to develop a peer-to-peer chat application. A peer-to-peer (P2P) application is an application primitive, where there is no dedicated central server nodes. Every node in the network can connect with each other and transfer data among themselves. In this P2P chat application, we consider a close group of friends who want to chat with each other. The chat application uses TCP as the underlying transport layer protocol. For P2P implementation, every instance of the chat application runs a TCP server (we call this as peer-chat server) where the chat application listens for incoming connections. The protocol details are as follows. The same process of the application also runs one or multiple TCP clients (based on the number of peers) to connect to the other users and transfer messages. Design Requirements: 1. The entire chat application runs under a single process. 2. Every participating user maintains a user_info table that contains – (a) name of the friend, (b) IP address of the machine where the chat application is running, (c) port number at which the peer-chat server is running. This table is static and shared a priori with all the participating users. 3. For the chat purpose, a user enters message using the keyboard. The message format is as follows: friendname/ where friendname is the name of the friend to whom the user wants to send message, and msg is the corresponding message. 4. The communication mode is asynchronous, indicating that a user can enter the message anytime. The console should always be ready to accept a new message from the keyboard, unless the user is already typing another message. Protocol Primitives: 1. As we mentioned earlier, every instance of the chat application runs a TCP server which binds itself to a well known port and keep on listening for the incoming connections. There can be a maximum of 5 peers (users), so a maximum of 5 connections need to be supported. 2. Once the server receives a connection, it accepts the connection, reads the data from that connection, extracts the message, and displays it over the console. 3. Once a user enters a message through keyboard, a. The message is read from the stdin, the standard input file descriptor. b. The application checks whether a client socket to the corresponding server already exists. If a client socket does not exist, then a client socket is created to the corresponding server based on the lookup over user_info table c. The message is sent over the client socket 4. If there is no activity over the client socket for a timeout duration, then the client socket is closed. As all the above functionalities are executed over a single process, you need a way to maintain multiple file descriptors, and handle them in an iterative way. This is accomplished by the select() system call. A flow diagram of the entire process is given next. Submission Instructions: The code needs to be written in any suitable programming language. You need to prepare a report that will contain the followings. 1. Documentation of the code along with compilation and running procedure, sample input and sample output Also include a makefile to compile your code. You need to submit the code and Makefile in a single compressed (tar.gz) file. Rename the compressed file as Assignment_4_Roll_no.tar.gz.