Question: How to write a simple request/response protocol in JavaScript in Packet Tracer? Heres the serialization: Both client queries and server responses have the same header

How to write a simple request/response protocol in JavaScript in Packet Tracer? Here’s the serialization:

Both client queries and server responses have the same header structure.

1 1 1 1 1 1

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

| Version | QR | RSRVD | ErrCode |

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

| |

QueryID

| |

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

| Data |

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

| ... |

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

· Version (4 bits): Protocol version - 0010 (binary) for your implementation

· QR (1 bit): 0 for query and 1 for response

· RSVD (3 bits): Reserved for future use. Should be all 0s.

· ErrorCode (unsigned byte): Error code for server (0 = No error, non-zero = Error (see list))

· QueryID (unsigned, big-endian, four-byte integer): Randomly generated ID that the client uses to map server responses to outstanding requests. It should be different for each query, and the client should use it to verify that the response and query IDs match.
For a query packet, the Data field simply contains an unsigned, big-endian, two-byte integer, which tells the server the maximum number of posts to return.

For a response packet, the Data field has the structure

1 1 1 1 1 1

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

| Number of Posts |

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

| Post List |

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

· Number of Posts (unsigned, big-endian, two-byte integer): Number of post records

· Post List: List of posts

A post is of the form

1 1 1 1 1 1

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

| Post Length |

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

| Char | ...... |

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

· Post Length (two-byte, big endian, unsigned int): Length (in bytes) of this post


Char (1 byte): ASCII encoded character (repeated length times)

Implement a UDP client that sends its query, receives the response, prints in a user-friendly manner the reply or error message to the terminal, and terminates. The client command-line parameters are the server IP/name, server port, and requested number of responses (e.g., client 129.62.148.1 5000 20).


Step by Step Solution

3.52 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

ANSWER UDP Client Create an instance of the UDP socket var udpSocket new dgramSocketudp4 Define the ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!