Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi guys, I need explantions and a hand for this project, Can anyone help me? Down are some indications for the project: To develop a

Hi guys, I need explantions and a hand for this project, Can anyone help me? Down are some indications for the project:

To develop a network Chatbot application over a noisy channel under the client-server model. The development implements a simple chat protocol similar to the Stop-and-Wait protocol studied in the class. In the client-server model, the reply from the server usually serves as the positive acknowledgement, and therefore no separate positive acknowledgement is required. Also, to simplify the task, timers are not used and a negative acknowledgement instead is sent to the client for errors detected in the clients request.

The two major programs in the application are the client and the server. The client sends a message to the server through a noisy channel. Errors are purposely generated randomly in the CRC-checksummed message based on the channels error rate. When the server receives a message, it calculates the CRC checksum to detect errors. If no error, a reply generated from the Chatbots rules engine in response to the clients message is sent to the client. Otherwise, a negative acknowledgment is sent back and the client retransmits the request. The chat continues until a termination message is sent by the client.

For the purpose of proof-of-concept and simplification, we unrealistically assume that no data is lost. Also, we assume that no error occurs in the reply and negative acknowledgements.

Protocol Description

Message Formats Three types of messages are used in the protocol. Their formats are described as follows:

1. Client request (fixed size = 45 bytes), sent from client to server

[ ID | LENGTH | PAYLOAD | CHECKSUM ]

ID: client identification; size = 3 bytes

LENGTH: actual length of payload in bytes; size = 1 bytes; value is 0 to 40

PAYLOAD: client message; size = 40 bytes

o Specialvalue:AterminationmessagecontainsBYEinanycombinationofcases.

CHECKSUM: calculated using CRC-8; size = 1byte 2.

2. Server reply, sent from server to client

[Hi|CLIENTID|! |PAYLOAD]

CLIENT ID: client identification; size = 3 bytes

PAYLOAD: server message; variable size

3. Negative acknowledgment, sent from server to client

[ NAK ]

ACK:size=1byte;value=1

Client Procedure

1. Prompts for client ID

2. Prompts for client chat message up to 40 characters long

3. Puts the message into the PAYLOAD field and completes the header information of the request.

4. Calculates CRC checksum for the request and places it in the CHECKSUM field.

5. Use an error function to introduce errors based on error rate

6. Transmits the request.

7. Receives reply from the server.

8. If the server reply is NAK then retransmits: go to step 3 (you may go to step 5 if the request is "buffered") else displays the message go to step 2 9. The procedure from step 2 to step 8 repeats until a termination message is sent by the client.

Server Procedure

1. Receives a request and calculates its checksum.

2. If remainder is 0 (i.e., no error) then generates a chat message from the rules engine sends reply (i.e., servers chat message) to the client else sends NAK to client

3. The procedure from step 1 to step 2 repeats until the server receives a termination message.

Requirements

1. Use the Link class provided by the instructor for the data communication.

2. Use the CRC-8 function .

3. Implement the protocol exactly as described, including the data format and procedure.

4. Design and develop a Chatbot rules engine that generates a message to respond to the client chat message.

The rules engine contains at least 5 different rules for the server to chat back, possibly based on the content, prefix, suffix, length of the client chat message and so on. The rules engine also handles the termination message properly.

5. Include a trace option.

For client trace on, the client program displays:

o OK,ifnoerrorgenerated

o Error, need retransmission, if error generated

For server trace on, the server displays the following information:

Message sender is: client_ID

Message length is: client_message_length

Checksum is: checksum_value

6. Error function uses a random number generator to determine whether to damage a request.

If a request is to be damaged, the probability of 1 error is 0.75 and 2 errors is 0.25.

Theoretically, every bit in a damaged message is equally likely to be altered. You may alter bits in the first byte of PAYLOAD without the loss of generality.

7. Input from user:

Client: probability that a request will be damaged (i.e. error rate), trace on/off, client ID

Server: trace on/off

8. Test your programs 5 times, each time with a different error rate: 0%, 50%, 60%, 75%, and 90%. 10 client chat messages should be sent in each test. Of course, the last message should be a termination message.

9. Display the following statistics after the communication terminates:

Total number of client chat messages

Total number of client request transmitted

Theoretical total number of transmission (= Total number of client chat messages / (1 - error rate))

Total number of chat messages damaged

Maximum number of retransmission for any single chat message

I am looking foward for a helpful hand.

Classes, This is what I got:

class CRC8 {

public byte checksum(byte[] data) {

short _register = 0;

short bitMask = 0;

short poly = 0;

_register = data[0];

for (int i=1; i

_register = (short)((_register << 8) | (data[i] & 0x00ff));

poly = (short)(0x0107 << 7);

bitMask = (short)0x8000;

while (bitMask != 0x0080) {

if ((_register & bitMask) != 0) {

_register ^= poly;

}

poly = (short) ((poly&0x0000ffff) >>> 1);

bitMask = (short)((bitMask&0x0000ffff) >>> 1);

} //end while

} //end for

return (byte)_register;

}

}

Driver class

// Examples showing how to invoke CRC8.checksum()

class CRC8Driver {

public static void printChecksum(byte result) {

// print out the checksum in binary

System.out.println("The 8-bit checksum w/o leading zeros is "+Integer.toBinaryString(result&0x000000ff)+".");

}

public static void main(String[] args) {

CRC8 crc8 = new CRC8();

// "Sender" appends 8 bits (i.e., one byte) of 0's to frame to compute checksum

byte[] data1 = {(byte)0X83, (byte)0x00};

byte[] data2 = {(byte)0X82, (byte)0x00};

byte[] data3 = {(byte)0X01, (byte)0x00};

byte[] data4 = {(byte)0X41, (byte)0x82, (byte)0x00};

byte[] data5 = {(byte)0X83, (byte)0x88, (byte)0x38, (byte)0x00};

byte[] data6 = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 0};

byte crc1 = crc8.checksum(data1);

byte crc2 = crc8.checksum(data2);

byte crc3 = crc8.checksum(data3);

byte crc4 = crc8.checksum(data4);

byte crc5 = crc8.checksum(data5);

byte crc6 = crc8.checksum(data6);

printChecksum(crc1);

printChecksum(crc2);

printChecksum(crc3);

printChecksum(crc4);

printChecksum(crc5);

printChecksum(crc6);

System.out.println();

// Remainder appended to frame for "transmission"

data1[1] = crc1;

data2[1] = crc2;

data3[1] = crc3;

data4[2] = crc4;

data5[3] = crc5;

data6[7] = crc6;

// Receiver computes checksum on checksummed frames

System.out.println("Checksum of checksumed frame w/o errors should be 0.");

printChecksum(crc8.checksum(data1));

printChecksum(crc8.checksum(data2));

printChecksum(crc8.checksum(data3));

printChecksum(crc8.checksum(data4));

printChecksum(crc8.checksum(data5));

printChecksum(crc8.checksum(data6));

System.out.println();

// Receiver computes checksum on checksummed frames with error on byte 1s bit 2

System.out.println("Checksum of checksumed frame data5 with errors is not 0.");

data5[1] ^= 0x04;

printChecksum(crc8.checksum(data5));

}

}

Another class we should work on:

public interface Link {

// Constructor information

/*

public Link (int senderPort, int receiverPort) throws Exception;

*/

// Send message in sendingBuffer of length lengthMessageSent

public void sendFrame(byte[] sendingBuffer, int lengthMessageSent)

throws Exception;

// Receive message and place in receivingBuffer and return its length

public int receiveFrame(byte[] receivingBuffer) throws Exception;

// Close connection

public void disconnect() throws Exception;

}

Receiver and sender link classes

static int senderPort = 3200; // port number used by sender

static int receiverPort = 3300; // port number used by receiver

public static void main (String args[]) throws Exception

{

int lengthMessageReceived = 0;

String messageToSend;

String messageReceived;

byte[] sendingBuffer = new byte[512];

byte[] receivingBuffer = new byte[512];

// Set up a link with source and destination ports

// Any 4-digit number greater than 3000 should be fine.

Link myLink = new SimpleLink(receiverPort, senderPort);

// Receive a message

lengthMessageReceived = myLink.receiveFrame(receivingBuffer);

// Display the message

messageReceived = new String(receivingBuffer, 0, lengthMessageReceived);

System.out.println("Message received is: [" + messageReceived + "]");

// Prepare a message

messageToSend = "OK!";

// Convert string to byte array

sendingBuffer = messageToSend.getBytes();

// Send the message

myLink.sendFrame(sendingBuffer, sendingBuffer.length);

// Print out the message sent

System.out.println("Message sent is: [" + messageToSend + "]");

// Close the connection

myLink.disconnect();

}

public class LinkSender {

static int senderPort = 3200; // port number used by sender

static int receiverPort = 3300; // port number used by receiver

public static void main (String args[]) throws Exception

{

int lengthMessageReceived = 0;

String messageToSend;

String messageReceived;

byte[] sendingBuffer = new byte[512];

byte[] receivingBuffer = new byte[512];

// Set up a link with source and destination ports

Link myLink = new SimpleLink(senderPort, receiverPort);

// Prepare a message

messageToSend = "Hello World! HaHa!";

// Convert string to byte array

sendingBuffer = messageToSend.getBytes();

// Send the message

myLink.sendFrame(sendingBuffer, sendingBuffer.length);

// Print out the message sent

System.out.println("Message sent is: [" + messageToSend + "]");

// Receive a message

lengthMessageReceived = myLink.receiveFrame(receivingBuffer);

// Display the message

messageReceived = new String(receivingBuffer, 0, lengthMessageReceived);

System.out.println("Message received is: [" + messageReceived + "]");

// Close the connection

myLink.disconnect();

}

}

simple link class

import java.net.*;

public class SimpleLink implements Link {

private DatagramSocket clientSocket;

private String hostname;

private InetAddress destination;

private int destinationPort;

// Set up a link between senderPort and receiverPort

public SimpleLink (int senderPort, int receiverPort) throws Exception {

// Open a UDP datagram socket for senderPort

clientSocket = new DatagramSocket(senderPort);

hostname = "127.0.0.1"; // loopback

destination = InetAddress.getByName(hostname);

// Port number

destinationPort = receiverPort;

}

// Send message in sendingBuffer of length lengthMessageSent

public void sendFrame (byte[] sendingBuffer, int lengthMessageSent) throws Exception {

// Create a packet

DatagramPacket sendPacket =

new DatagramPacket(sendingBuffer, lengthMessageSent, destination, destinationPort);

// Send a message

clientSocket.send(sendPacket);

}

// Receive message and place in receivingBuffer and return its length

public int receiveFrame (byte[] receivingBuffer) throws Exception {

// Create a packet

DatagramPacket receivedPacket =

new DatagramPacket(receivingBuffer, receivingBuffer.length);

// Receive a message

clientSocket.receive(receivedPacket);

return receivedPacket.getLength();

}

// Close connection

public void disconnect() throws Exception {

// Close the socket

clientSocket.close();

}

}

Thank you.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

Write short notes on Interviews.

Answered: 1 week ago

Question

Define induction and what are its objectives ?

Answered: 1 week ago

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago