Solved–Register and Discover-Assignment 3– solution

$35.00 $24.00

Programming Assignment (Turned in by one group mate) This programming assignment implements a Chat Room. The ultimate objective is to develop a basic Chat Room allowing remote users to discover a partner to chat with. Your code includes two functions: Register and Discover: Develop a simple UDP client-server application that allows a client to REGISTER…

You’ll get a: . zip file solution

 

 

Description

5/5 – (2 votes)

Programming Assignment (Turned in by one group mate)

This programming assignment implements a Chat Room. The ultimate objective is to develop a basic Chat Room allowing remote users to discover a partner to chat with. Your code includes two functions:

  1. Register and Discover: Develop a simple UDP client-server application that allows a client to REGISTER to chat and DISCOVER a potential chatting partner.

  2. Chat: Develop additional features to allow registered clients to chat directly through TCP.

We assume that the Internet is perfect: no packet is corrupted, lost, reordered or duplicated.

Your server must interoperate/work with any other group’s (working) client. Similarly, your client must interoperate/work with any other group’s (working) server.

To make it easy, a client can chat with any available client, rather than one out of a list of “contacts”.

Part 1: Register and Discover

You must design and implement the client in C and the server in a language of your choice. All integers are encoded in the network byte order.

  1. The Server

    1. The server accepts as command line: Server ServerPort# where ServerPort# is the port on which the server is accepting requests. To run your server, set ServerPort# to 10010 + 5*GID(server). For example, if your group ID is 1, the server must be run/tested on Port # 10010 + 5*1 = 10015.

    2. When the server gets a request 0x4A6F7921PhPlGID from client NewClient that contains the magic number 0x4A6F7921, the group ID GID(client) (one byte) (GID(client) is the number of the group who designed/implemented the client.), and a port number P (PhPl, where Ph is the most significant byte of the port, and Pl is the least significant byte of the port), it reacts depending on whether there is a waiting client or not:

      1. If there is no client waiting, the server registers the IP address of the Requesting Client and the port number P, and responds with a datagram that contains 0x4A6F7921GIDPhPl where 0x4A6F7921 is the magic number, GID(server) is the GID of the owner of the server, and PhPl is the port number in the request.

      2. If there is a waiting client WaitingClient, the server responds with a message that contains:

        1. The magic number 0x4A6F7921

        2. The IP address of WaitingClient (network byte order)

        3. The port number of WaitingClient. (network byte order)

        4. The GID(server) where GID(server) is the group ID of the group implementing the server.

Furthermore, the server flushes any record of WaitingClient.

    1. If the request is invalid, the server must send a 7 byte message 0x4A6F7921GID00XY that contains an error code.

      1. If the request does not contain a magic number, XY0 is set to 1 (XYi is the ith bit in the byte XY. XY0 is the least significant bit)

      2. If the length is not correct, XY1 is set to 1

      3. If the port number is out of range, XY2 is set to 1. The port P is invalid if P is out of the range [10010+5*GID(client), 10010 + 5*GID(client)+4] (example, if your GID(client) is 2, the range is [10020-10024]). GID(client) is the number inside the request.

  1. The Client implemented by Group # GID (must set the TCP server within [10010+5*GID(client), 10010 + 5*GID(client)+4].)

    1. The client accepts as command line: Client ServerName ServerPort MyPort where:

      1. Client is the executable

      2. ServerName is the server hostname

      3. ServerPort is the port where the server is running

      4. MyPort is the TCP port where the client is willing to chat. MyPort must be in the range [10010+5*GID(client), 10010 + 5*GID(client)+4]. If you are group 10, you must set MyPort in the range [10060, 10064].

    2. The client sends a request to the server named ServerName at port ServerPort. The request must of the form 0x4A6F7921PhPlGID , as previously described in the server. GID(client) is the number of the group who designed/implemented the client.

    3. When the client receives a valid response, it prints it out on the screen (magic number and (if available) the IP address and the port number in the message). If the response is not valid, it must print out an error message.

Part 2: Now, let us chat

You must design and implement a server and a client.

  1. The Server

The server is exactly the working server from Part I

  1. The Client

The client is an improved working client from Part I with the following addition:

When the client receives a response, it reacts depending on the server’s response:

  1. If the response contains only a magic number, then the client establishes a TCP server and waits for some client to chat with. It will print on the screen its status: waiting for a partner to connect. After printing out its status, the client will wait for a client to connect. As soon as a TCP connection is established, the client must prompt the user to input some message to send. The client must send out any message input by the user and print out any message it receives.

  2. If the response contains a magic number, an IP address IPServer, and a port number PN, then the client must establish a TCP Client and connect to the server at IP address IPServer and Port number PN. After the connection is established, the client must

  1. Prompt a user to enter a message msg

  2. Send the message msg.

  3. Go to 1)

The client must send out any message input by the user and print out any message it receives.

To stop chatting, a user must enter “Bye Bye Birdie”. If the user enters this special message, the client must send out that message and close the connection. The chat ends whenever a client receives the message “Bye Bye Birdie”.

Grading:

1) 50 points per program (One client and one server)

2) Code does not compile on a Tux machine: 0% credit

3) Code compiles on Tux machines but does not work: 5% credit

4) Code compiles and interacts correctly with counterpart from the same group: 70% credit

5) Code compiles and interacts correctly with counterpart from other groups: 100% credit

Advice to complete these exercises:

This is just an introduction to socket programming: I advise to work ACTIVELY to implement these programs.

How to get started?”:

This is just an introduction to socket programming: I advise to work ACTIVELY to implement these programs.

Step 1: download, compile, and execute Beej’s sample programs (UDP-client.c and UDP-server.c )

Step 2: get familiar with this code: study key socket programming calls/methods/functions

Step 3: improve the server to echo (send back) the string it received.

Step 4: improve the client to receive the echo and print it out.

Step 5: SAVE the improved versions (you may need to roll back to them when things will go bad)

Step 6: All you need now is “forming” your messages based on the specified format (lab 1 protocol).

Help Tools:

Besides this lab, I posted the following programs:

  1. UDP-server.c (Beej’s datagram server)

  2. UDP-client.c (Beej’s datagram client)

  3. UDPServerDisplay.c : this program is a modification of Beej’s UDP server: it takes as input a port number to run on and displays in hexadecimal what it receives.

  4. TCPServerDisplay.c : this program is a modification of Beej’s TCP server: it takes as input a port number to run on and displays in hexadecimal what it receives.

  5. packedStruct.c : this program shows how to create a “packed” struct.

What to turn in?

  1. Electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named lab1-name1-name2 where name1 and name2 are the last names of two teammates. Zip the folder and post it on Canvas. Submit separately (not inside the zipped folder) the report as a Microsoft or PDF file. A penalty of 10 points will be applied if these instructions are not followed.

  1. Your report must:

    1. state whether your code works

    2. Clearly explain how to compile and execute your code. If the TA needs your presence to compile and execute your code, then a 30% penalty will be applied.

    3. If needed, report/analyze (as appropriate) the results. The quality of analysis and writing is critical to your grade.

Good writing and presentation are expected.

If the TA is unable to access/compile/execute your work based on your report, a 30% penalty will be applied.

If the turn in instructions are not correctly followed, 10 pts will be deducted.