Advanced Computer Communications (CNCO3002)
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
Advanced Computer Communications (CNCO3002)
Assignment
Simple Network Chat
2022
A. Overview
The objective of this assignment is to develop two complementary network application programs (a CLIENT and a SERVER) that implement a simple chat system, called Simple Network Chat (SNC). Note that SNC does not follow the Internet Relay Chat (IRC) specified in RFC 1459 and its revisions in RFC 2810, RFC 2811, RFC 2812 and
RFC 2813.
SERVER |
CLIENT B |
CLIENT C |
The figure shows one SNC server (SERVER) and three SNC clients (CLIENT). A user (e.g., you or your grader) uses a program (CLIENT) to connect to the SERVER. Once connected, a CLIENT canjoin the SERVER to communicate (shown as dashed lines) with other CLIENTs that have joined the SERVER. For example, CLIENT A can send a message “Hello” to CLIENT B or CLIENT C by sending the message to the SERVER, which will send that “Hello” to CLIENT B or CLIENT C, shown as the solid lines in the figure.
B. SNC Commands
The SNC CLIENT and SERVER use only the following SNC commands. Each command is not case-sensitive, i.e., a command can be in lower-case or upper-case or a combination of lower/upper case.
A user gives a command to a CLIENT using keyboard, which is shown on the screen, and the CLIENT sends the command to the SERVER if the command contains no error. It is important that each CLIENT and the SERVER independently check for the correctness of each command. If a command contains error, a CLIENT must inform the user and does not send the message to the SERVER.
a. JOIN <nickname> <realname> is used at the beginning of a connection to specify the nickname and realname of a new user. A nickname is in one word. Each
nickname and each realname has a maximum of 20 characters.
The following gives an example of the JOIN command:
JOIN Jim James Cook
Receiving this command, the SERVER must ensure that the user has not previously joined the SERVER, i.e., <realname> does not exist in the SERVER. The SERVER must notify the CLIENT if the user has joined SNC. The SERVER must also ensure that no other users use the same nickname. If the nickname has been used by other user, the SERVER asks the CLIENT to repeat the command with a new nickname.
For each new user with unique nickname, the SERVER stores the information about the user (e.g., nickname, realname, and the IP address and Port number of the CLIENT) in its record, sends a welcome message to the CLIENT, and informs other users about the new user.
Receiving message from the SERVER, a CLIENT shows the message to the screen in a new line. For example, the CLIENT Jim will show the following text:
Server: Jim, welcome to SNC!
Each other CLIENT will receive and print the following text to the screen in a new line:
Server: A new user Jim has joined SNC!
b. WHOIS <target> is used to ask information about a user with nickname <target>. The following gives an example of the WHOIS command:
WHOIS Jim
The SERVER sends an error message to the CLIENT if there is no user with nickname <target> in the SERVER’s record. Otherwise, the SERVER sends the requested information, i.e., the nickname and realname of <target>, to the CLIENT.
For the example, a CLIENT that asks for “WHOIS Jim” will receive and print the following text to the screen in a new line:
Server: Jim James Cook
c. MSG <target> <text> is used to send text messages between users, where <target> is the nickname of the recipient of the message. Each <text> has a maximum length of 256 characters in one line.
For example, user Jim types the following to send <text> to user Red: MSG Red I like the assignment!
A CLIENT, e.g., user Jim, sends the command to the SERVER. Receiving the command, the SERVER sends <text> together with the sender’s nickname, e.g., Jim, to the CLIENT that has nickname <target>, e.g., Red.
If there is error in the command (e.g., there is no <target> in the command, there is no user with nickname <target>, or there is no <text>) the SERVER sends an error message to the CLIENT.
Receiving the message, the CLIENT with nickname <target>, e.g., Red, prints the message to the screen in a new line.
For the example, the screen of CLIENT Red will show the following text:
Jim: I like the assignment!
d. TIME is used to query the local time of the SERVER. The SERVER sends its local time to the CLIENT. The CLIENT prints the time to the screen in a new line after receiving the time from the SERVER.
e. ALIVE is used by a CLIENT to inform the SERVER that the CLIENT is still active. Receiving ALIVE, the SERVER reinitializes the allowed idle time for the CLIENT to max_idle_time, and sends an OK message to the CLIENT. The CLIENT shows the OK message to the screen in a new line. Write your own OK message.
The SERVER terminates a CLIENT connection if the CLIENT is idle (i.e., does not send any command to the SERVER) within max_idle_time. The SERVER then sends a termination message to each remaining CLIENT that will print the message to the screen in a new line. Write your own tremination message.
Each idle user who wants to keep the connection must send the ALIVE command to the SERVER before max_idle_time period.
f. QUIT is used by a CLIENT that wants to stop chatting.
The SERVER sends a good bye message and closes the connection to the CLIENT. The SERVER also informs each remaining CLIENT that the CLIENT has terminated its session.
For example, CLIENT Jim’s screen may show the following text:
QUIT
Server: Bye Jim!
Each other CLIENT’s screen will show the following text:
Server: Jim has stopped chatting.
C. Program Implementation
1. Your program must be written in C language using TCP/IPv4 sockets.
2. The concurrent SNC SERVER uses one thread to serve each connecting client. The SERVER can accept up to m connecting clients simultaneously. The value of m and max_idle_time must be the arguments passed to the SNC SERVER when the SERVER is started. The valid numbers for these arguments are:
• m: 1 to 10.
• max_idle_time: 1 to 300 seconds.
For example, the SNC SERVER is run as follows:
server 5 200
3. The SNC CLIENT must be started with:
client IP-address port
The IP-address (in dotted decimal notation) and Port (your assigned port number) are the SERVER’s address and port.
Once the SNC CLIENT is connected to the SNC SERVER, the SNC CLIENT waits for user command, and a prompt “ID>” is shown on the screen, where ID is your student ID.
4. The SNC SERVER is responsible for checking the validity and syntax of its CLIENT’s command. Similarly, the SNC CLIENT should also check the validity/syntax of its user commands.
5. Proper handling of mutual exclusion and race conditions is required.
6. You must check for error return from each system call, close every created socket, and remove all other created resources once your program terminates.
7. You MAY make your own assumptions/requirements other than those already given. However, YOU HAVE TO DOCUMENT ANY ADDITIONAL ASSUMPTIONS / LIMITATIONS FOR YOUR IMPLEMENTATIONS.
D. Instruction for submission and assignment demonstration
1. Assignment submission is compulsory. Late submission is allowed. As stated in the unit outline, the penalty for late submission is as follows:
• For assessment items submitted within the first 24 hours after the due date/time, students will be penalised by a deduction of 5% of the total marks allocated for the assessment task;
• For each additional 24 hour period commenced an additional penalty of 10% of the total marks allocatedfor the assessment item will be deducted; and
• Assessment items submitted more than 168 hours late (7 calendar days) will receive a mark of zero.
Due dates and other arrangements may only be altered with the consent of the majority of the students enrolled in the unit and with the consent of the lecturer.
2. You must
(i) put your program files, e.g., server.c, client.c, makefiles, and other required files, in your home directory named CNCO3002/Assignment for marking by your grader, when needed, and
(ii) submit the soft copy of an assignment report to the unit Blackboard (in one zip file), i.e., YourID_Assignment.zip.
3. The soft copy of your report, MUST include:
• A signed cover page (i.e., declaration of originality). The declaration form is available from the unit Blackboard. By signing the form, among others, you agree on the following two statements:
1. The work I am submitting is entirely my own, except where clearly indicated otherwise and correctly referenced.
2. Even with correct referencing, my submission will only be marked according to what I have done myself, specifically for this assessment. I cannot re-use the work of others, or my own previously submitted work, in order to fulfil the assessment requirements.
• Software solution of your assignment that MUST include (i) all source code for the programs with proper in-line and header documentation. Use proper indentation so that your code can be easily read. Make sure that you use meaningful variable names and delete all unnecessary / commented code that you created while debugging your program; and (ii) readme file that, among others, explains how to compile your program and how to run the program.
• Detailed discussion on all shared data structures used in the server, and how any mutual exclusion / thread synchronization is achieved on shared resources, e.g., memory, server’s record, and what threads access the shared resources.
• Description of any cases for which your program is not working correctly or how you test your program that make you believe it works perfectly.
• Sample inputs and outputs from running your programs. For each sample output, you MUST explain if the output is correct or incorrect.
Your report will be assessed (worth 20% of the overall mark for the Assignment)
4. Assignment demonstration
• You are required to demonstrate your program. The time schedule for the demonstration will be announced later.
• For the program demo, you MUST keep the source code of your programs in your home directory, and the source code MUST be that you have submitted.
• The programs must run on any computer in the department labs.
Failure to meet these requirements may result in the assignment not being marked.
2022-09-08