Skip to content

Network Protocol (There And Back Again, A Packet's Tale)

akersten edited this page Jan 5, 2013 · 12 revisions

The communication between the Webfront and the backend is central to this whole thing working. For brevity's sake, I'll keep this page rather short and focus on only what matters.

Backend

The backend is listening on port 11211 for incoming UDP packets. It is looking for something like this: [64-character Service Master Key][Other stuff]

The 64-character SMK must match AF19914DFE944E38FE8CED6E490D1BB16C6A20F7F36237753A2EAF5BF2503536, otherwise the request will not be serviced. (That's the default key - change it before you deploy! See the Testing vs. Release section on the main page.) [Other Stuff] can be anything, but it must fit within the buffer which is currently 1024 bytes long (-1 for the null terminator, -64 for the SMK = 959 usable bytes per packet).

Ideally, [Other stuff] will consist of some kind of "opcode" and then parameters, which will be interpreted specifically for that "opcode".

It's probably important to mention that this is a text-based protocol - this is all ASCII and human-readable, just because it's easy to do in PHP and binary encoding is less easy to do. We've got the bandwidth to spare.

Opcode Specification

Opcodes are 4 characters long (but not necessarily printable characters - they can use any of the 2^32 possible binary encodings for those bits). Implemented opcodes are listed below.

Stop

Terminates the server. Will need to be manually restarted.

0x00 00 00 01

No parameters.

Echo

Echoes the payload back to the Webfront listen port.

0x00 00 00 02

No parameters.

Client request state update

Triggers the server to package its global state and send it to the Webfront which can then display it for the client.

0x00 00 00 03

No parameters.

TODO: The backend is also listening on insert port here for status updates from the cRIO itself (right?)

Webfront

The webfront sporadically listens on port 11911. It does this listening when it expects a global state update from the backend, which it should receive and use to update the global state. The Webfront uses this global state information and propagates it to the UI for display to the user. This global state is the latest information regarding the fountain as far as the Webfront is concerned, and it is refreshed every insert interval here by a client-side AJAX request to the Webfront to refresh the information. The Webfront then sends an update request to the server and starts listening on port 11911 for a global state update.

Clone this wiki locally