At Rainway, we scrape millions of images every single month. For this homework assignment, you will be creating a tool that communicates with our metadata service over a WebSocket to request an image.
The first packet you will need to send is a “resource token request” with these values.
If the metadata service can process your request, you will receive a resource token.
Your mission is simply to display this token as a list of 16 bytes. (In this assignment, you don’t have to worry about using the token to download the image.)
The API uses a binary protocol. This means you’ll receive and send a binary packet over the WebSocket. You will have to encode the values above into an array of bytes. Then, when you get a response, you’ll have to read values back out of an array of bytes.
To connect to the WebSockets metadata service, use the following URL:
If malformed or incorrect data is sent to the metadata service, your connection will be terminated.
- You may Google as much as you need to but please do not copy-and-paste code.
- You must complete this task using any language and libraries you like. It can be a console application that connects to the server and displays the token once it has it.
All data types should be written and read using little-endian byte order.
- bool: A value that stores either
false(0). Takes up 1 byte.
- byte: An unsigned 8-bit integer value. Takes up 1 byte.
- int32: A signed 32-bit integer value. Takes up 4 bytes.
- uint32: A unsigned 32-bit integer value. Takes up 4 bytes.
- uint64: A unsigned 64-bit integer value. Takes up 8 bytes.
byte means an array of bytes that lasts until the end of the packet.
Every packet begins with a unique “packet type” ID (uint32), followed by some fields, as described below.
First, you send a Resource Token Request to the server:
Resource Token Request (ID = 9062)
|Packet Type||uint32||The number 9062|
|Resource ID||uint32||A unique identifier for the desired remote resource|
|TTL||byte||Sets the amount of time (in minutes) the resource will be available|
|Use Cache||bool||Defines whether or not resource downloads will use the CDN|
The server will respond with a Resource Token Response:
Resource Token Response (ID = 5291)
|Packet Type||uint32||The number 5291|
|Timestamp||uint32||A unix timestamp of when the server began responding|
|Resource Token||uint64||A token that can be used to download this image|
This Resource Token is your final answer. Display it on the screen in decimal.
For extra credit, you can complete the rest of the assignment.
Use your token to send a Download Resource packet and begin a download:
Download Resource (ID: 9414)
|Resource Token||uint64||A secure token for accessing and reading a resource|
The server will respond with multiple Resource Chunk packets:
Resource Chunk (ID: 4292)
|Group ID||uint32||Identifies the group the current chunk belongs to|
|Index||int32||The index of the current chunk in the overall group|
|Is Last||bool||Indicates whether the current chunk is the last one|
|Data||byte||An array of bytes that represents part of a resource|
Reassemble the JPEG file from these chunks and save it to disk. What could it be?!
Thank you for submitting your solution. We will get back to you as soon as possible.