[SOLVED] COP4600 Ex8-Networking

30 $

SKU: 855434236457635 Category: Tag:

Ex8_-_Networking

Overview

This exercise serves as a brief introduction to TCP servers and the network toolset. In this activity, you will create a “wall” application, in which a single user can connect in order to “tag” (leave a message on) the wall. Wall programs were common in the days of Bulletin Board Systems (BBSs) before other Internet services became popular. As connections were made via telephone hardline dial-up, only one user could connect at a time, so the “wall” program served as a community board:

As text mode screens are generally 25 rows and 80 columns, a limited number of wall messages can be held; when the wall is “full”, the oldest message is removed from the message queue, and the new message is added to the end (first-in-first-out).The server and client must communicate through a TCP socket (in C or C++) and must compile and run on Reptilian. The wall’s state should be maintained even between connections. The netcat command line utility should be used to test the server.

Specification

Your server will run as a standalone program from the command line and will use the protocol specified below.

Command Line Execution

The server program will take up to two parameters, optionally – the maximum number of messages stored and the port. If not provided, the port should default to 5514, while the number of messages should default to 20:

$ ./wallserver Queue size 20, Port 5514

$ ./wallserver 30 Queue size 30, Port 5514

$ ./wallserver 35 7777 Queue size 35, Port 7777

Server Behavior

When a client connects, the server should send the wall’s contents and a prompt as shown below (Figure 2a). If there are no message entries, it should instead send “[NO MESSAGES – WALL EMPTY]” (Figure 2b).

Wall Contents————-Ted: Iron Maiden?Bill: Excellent!Liz: Look! I am a human doing human things! Enter command: _
Figure 2a. Wall display with contents. Figure 2b. Wall display without contents.

The server will accept four distinct commands – clear, post, kill, and quit. For commands that do not cause the user to disconnect (kill and quit), the server should send the wall’s contents and prompt the user for an additional command as shown in the example output.

Enter command: clear↵Wall cleared.Wall Contents————-[NO MESSAGES – WALL EMPTY]

clear

Clears the wall of all entries on the wall. In addition, the server should send a message indicating that the wall has been cleared. In addition, the server should send the wall’s contents to verify that the wall has in fact been cleared out correctly.

Wall Contents————-Jimmy Dean: Try my breakfast delights!Johnny 5: I’m alive!! Enter command: post↵Enter name: Bobo↵Post [Max length 74]: Hullo.↵Successfully tagged the wall. Wall Contents————-Johnny 5: I’m alive!!Bobo: Hullo. Enter command: _

post

Indicates the user wishes to tag the wall. The user should be prompted for their name, followed by a message. The entire post should not exceed 80 characters (including name and separator), so the maximum length of the message should be indicated to the users. If the message is too long, the server should display the message “Error: message is too long!”; otherwise, it should display “Successfully tagged the wall.

If the wall is “full” (the number of messages stored has reached the maximum), the oldest message (at the top) should be removed from the wall to make room for the new message post. Following the post attempt, the wall’s contents should be displayed and the user prompted for the next command. An example (with queue size 2) is shown on the right.

Wall Contents————-Jimmy Dean: Try my breakfast delights!Enter command: post↵Enter name: Johnny 5↵Post [Max length 70]: I’m alive!!! ↵ Successfully tagged the wall. Wall Contents————-Jimmy Dean: Try my breakfast delights!Enter command: post↵Enter name: ~~~[[[[[[[[[[[THE PLAGUE]]]]]]]]]]]~~~↵Post [Max length 40]: 12345678901234567890123456789012345678901↵Error: message is too long!
Enter command: kill↵Closing socket and terminating server. Bye!$ _

kill

Causes the server to shut down (terminate), and close the socket, disconnecting the user.

Enter command: quit↵ Come back soon. Bye! $ _

quit

Displays a termination message and closes the client’s socket, but does not shut down the server or clear the wall.

Debugging

It is recommended that students debug their server using the netcat command line utility (with alias nc). To do so, run your server in one ssh session, then open another and run netcat:

$ ./wallserver 2↵ Wall server running on port 5514 with queue size 2.Students are recommended to $ netcat localhost 5514 ↵Wall Contents————-Pigeon: You’ve got mail. Err, I mean, cooo. Coooo. Enter command: quit↵ Come back soon. Bye! $ _

Submissions

You will submit the following at the end of this exercise:

  • Compressed tar archive (tar.gz) for the server and its Makefile
  • Screenshot of netcat connecting to the server to show its function in detail (described below)

Compressed Archive (ex8.tar.gz)

Your compressed tar file should have the following directory/file structure:

To build the server program and run it, we will execute these commands:

$ tar zxvf ex8.tar.gz $ cd ex8 $ make $ ./wallserver [lines] [port]

 

Screenshot

Run the server with a message queue size of 5 and connect via netcat, running the following commands: 1) Post two messages successfully and one that fails due to being too long

  • Clear the server’s wall
  • Post to the wall again
  • Quit from the server
  • Reconnect to the server
  • Kill the server
  • Attempt to connect again to show that the server has terminated

You may use two screenshots if you cannot fit all the commands with a single capture.

Resources

https://linux.die.net/man/2/socket – documentation for a function that you’ll be getting comfortable with https://www.unixfu.ch/usenetcatinsteadoftelnet/ – an http example using netcat

https://linuxhandbook.com/jobscommand/ – as an alternative to opening multiple terminals, you can keep the server running in the background by learning how to manage jobs (not necessary to complete the exercise, but may be interesting to students that like working in the terminal)

Shopping Cart
[SOLVED] COP4600 Ex8-Networking
30 $