Network Chat Application Lab THIS IS AN INDIVIDUAL ASSIGNMENT. DISCUSSING THE LAB EXERCISES IS ALLOWED, BUT THE SUBMISSIONS MUST BE UNIQUE. SHARING OF CODE IS NOT ALLOWED. Introduction to Computer...

1 answer below »
using raspberry pi


Network Chat Application Lab THIS IS AN INDIVIDUAL ASSIGNMENT. DISCUSSING THE LAB EXERCISES IS ALLOWED, BUT THE SUBMISSIONS MUST BE UNIQUE. SHARING OF CODE IS NOT ALLOWED. Introduction to Computer Science and Engineering Networking Chat Application Lab Note that this lab may be developed on any Linux distribution, but you must run the application against a grader's Raspberry Pi from your Raspberry Pi to receive a grade for the lab. Introduction In this lab, we will borrow some code from the Computer Engineering Internet of Things / Networks course to develop a simple chat application. In doing so, you will also learn about a simple UDP network protocol and server-client network communications. You will also learn more about the concepts in this lab in CSE 3318 (Algorithms and Data Structures), CSE 3320 (Operating Systems), CSE 4352 (IoT/Networks), and CSE 4344 (Networks). Programming client-server applications is a very common task for Computer Engineering, Computer Science, and Software Engineering graduates. Network Quick Primer: When data is sent on an Ethernet connection in many applications, the data is sent between IP address and port pairs (collectively called socket addresses). The IP addresses we will use in the lab use the IPv4 protocol. An IPv4 address is 4 octets (4 bytes) long. In the lab, all the addresses are numbered 192.168.1.x, where x is a number between 1 and 254. To configure your RPi to operate on the lab network, you should enable DHCP so your RPi will automatically get a unique address on the lab network. This will allow you to send data to and receive data from other computers in the lab. A common implementation for communication uses a server and a client. For instance, when you use a web browser to connect to a web site, the browser is a client and the web site is a server. A physical or virtual machine may provide many services. Port numbers are used to expose services to external users using well known port numbers for each service. For instance, SSH and SFTP connect to a server using port 22 and web servers often use port 80. So when a web browser tries to get access a web site, it contacts the IP address at port 80. When port 80 is accessed, traffic is routed to the web server to process the get and post requests from the web browser. When port 22 is accessed, an SSH server handles the traffic. There are two primary IP protocols that are used to send data on these ports – Transport Control Protocol (TCP) and User Defined Protocol (UDP). TCP is more complicated as it contains complexity to reliably send large files consisting of many packets of data. When you surf the Web, the HTTP protocol uses TCP. UDP on the other hand is very simple by sending packets of data just once, so there is a chance for a packet of data to get lost. So the trade-off is complexity vs simplicity. Network Use for Chat App: For our lab, we will use the UDP protocol and implement a client and server system for a chat application. The server will monitor port 4096 and the client will monitor port 4097 for inbound UDP traffic. Another way of saying this is that the client will send messages to port 4096 and the server will send messages to port 4097. The choice of 4096 and 4097 are arbitrary, but are required for this project so the chat applications can inter-operate. In our lab, you can send a string using the provided sendData function: bool sendData(const char ipv4Address[], int port, const char str[]) You can receive a string using the provided receiveData function: void receiveData(char str[], int str_length) The string value you send is simply the text you want to send in the chat session. To start the chat, one of the users starts their chat application as a server, which waits to accept an initial string. The other user starts their chat application as a client and sends an initial message to the server. In both applications, users alternate turns and send their messages to each other. Application Requirements – General: You should write your lab solution in a file chat.c, that includes the udp.h header. When you compile the code, you will use the following command: gcc -o chat chat.c udp.c Application Requirements – Command Line: The application is named chat. Invoking the application requires 2 additional options – the IP address of the remote machine you want to reach and the operating mode of the application (client or server). The mode will indicate whether the application starts as a: - Server awaiting text from a client - A client sending text to a server The command line syntax is: ./chat REMOTE_IP MODE To start as a server awaiting an initial chat message from 192.168.1.x, the command line is: ./chat 192.168.1.x server To start as a client sending an initial chat message to 192.168.1.y, the command line is: ./chat 192.168.1.y client Your code solution should: - Have a main function, void main(int argc, char *argv[]) - Verify that there are 3 arguments (argc == 3) - Once the arg count is verified: - the IP address should be stored in a variable - The last argument (mode) is verified as “server” or “client” and stored in a variable Application Requirements – Listener Port Startup for Both Client and Server: On startup, the application should open a socket that listens for inbound messages from the remote IP addresses’ port. A call to bool openListenerPort(const char ipv4Address[], int port) with the remote address from the command line and the correct port to monitor (4096 for server or 4097 for client). If the function does not return a true condition indicating success, you should show the error and exit the application. Application Requirements – Receiving Data: Wait for a message with the following call: void receiveData(char str[], int str_length) where str[] is a string in your program that will be filled with the message and str_length is the size of the string. The str_length is passed to ensure that a message longer than the string size is not stored, mitigating a common method used to insert viral code by overflowing the buffer. This function will not return until a string has been received from the client. Once the string has been received or if an error occurs, display the string on the console. Application Requirements – Sending Data: Ask the user to enter a string to send and then send an invitation using the following call: bool sendData(const char ipv4Address[], int port, const char str[]) with the remote address from the command line and the remote port to which you want to send the message, and the string to send. Application Requirements – Shutdown: After a client or server receives or sends the chat message “QUIT” - Release the socket used in the listener port using the following call: void closeListenerPort() - Exit the application Example of Chat Session: 1. Client sends “ABC” 2. Server sends “DEF” 3. Client sends “QUIT” and both the server and client terminate. Networking Lab Worksheet Name __________________________ Course/Section _______________ Please complete the following steps to complete the network game lab: 1. Configure your RPi to use DHCP and get an address automatically. Use the ifconfig command to get the address that is assigned by the DHCP server located near the lecturn at the front of the lab. The IPv4 address should be 192.168.1.x. Please note the value x each time to start up your hardware in the lab. Others will need your full IPv4 address for their chat application to contact your RPi. 2. Create your application in a file called chat.c, following the requirements in the General Section. Build the project with the udp.c to make sure you are able to proceed. NOTE: You can actually open up two copies of the application in two bash shells and play a game between the two application instances by using the 192.168.1.x address from step 1. You can also use a special loopback address of 127.0.0.1 to chat between two application instances on your RPi. 3. Add command line argument support to your application, following the requirements in the Command Line Section. You must determine whether you will be a server or client and know the remote address of the remote chat program’s RPi. 4. Add code to open a listener port so you can receive messages from other users, following the requirements in the Listener Port Startup Section. 5. If the application starts as a server: a. Wait for a message to be received from the client b. Display the received message c. If “QUIT” was received, close the listener port following the requirements in the Shutdown Section d. Ask the user to enter a message to send to the client e. Send the message to the client f. If “QUIT” was sent, close the listener port following the requirements in the Shutdown Section g. Repeat a-f until the program exits 6. If the application starts as a client: a. Ask the user to enter a message to send to the server b. Send the message to the server c. If “QUIT” was sent, close the listener port following the requirements in the Shutdown Section d. Wait for a message to be received from the server e. Display the
Answered 2 days AfterNov 07, 2021

Answer To: Network Chat Application Lab THIS IS AN INDIVIDUAL ASSIGNMENT. DISCUSSING THE LAB EXERCISES IS...

Abhishek answered on Nov 10 2021
116 Votes
Page | 4
Raspberry PI 3 model A+ (counting appropriate power supply or utilizing a cell phone miniature usb charger with at minimum 3A) or more
current Raspberry PI board,miniature SD card (no less than 16 GB, basically class 10) .For this undertaking, I will utilize a less expensive Raspberry Pi 3 model A+. Additionally more current Raspberry PI sheets will work.We'll utilize a light form of Raspberry PI OS with preconfigured WiFi access and SSH administration, so there will no need of consoles/HDMI links.In PC organizing, the User Datagram Protocol is one of the center individuals from the Internet convention suite. With UDP, PC applications can send messages, for this situation, alluded to as datagrams, to different hosts on an Internet Protocol organization.
Begin introducing Raspberry PI OS Lite. -
We'll work on Rocket.Chat establishment by utilizing Snap. Login through SSH and type from terminaly:
sudo apt update
sudo apt upgrade
sudo apt install snapd
It is a connectionless convention and not solid. It isn't utilized in other talking applications like Facebook and WhatsApp. The correspondence speed is relatively quick than the TCP convention. It is utilized in web-based video surfing and gaming. In this arrangement, Server just gets messages and the customer can just send messages. We can use the attachment library in python.
import socket
#AF_INET used for IPv4
#SOCK_DGRAM used for UDP protocol
s =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here