Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

ANSWER UDP Client Create an instance of the UDP socket var udpSocket new dgramSocketudp4 Define the ... 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

Statistics The Art And Science Of Learning From Data

Authors: Alan Agresti, Christine A. Franklin, Bernhard Klingenberg

4th Edition

133860825, 321997832, 133860914, 978-0321997838

More Books

Students also viewed these Mathematics questions