Server/ Website Communication
The Communication is handled by a WebProvider, wich is a central server in a star pattern. This server waits for clients and applies theire changes and distributes these changes to all interested clients.
The provided WebProvider listens on port 8089 and is accesed by the Controller which does a protocoll-upgrade to enable full block data-writeing and PHP-instances which provide data for a webside or ServerSendEvents(SSE)
The communication protocoll is a use-case limmited binary protocol which sends a one byte command followed by a one byte datatype byte followed by a specific number of data bytes specified by the command and datatype.
Commands:
Byte | Name | Usage | Data Content |
---|---|---|---|
0x01 | Set Data | sets a part of specified data or all if in blockmode | 2 bytes, index and value (or all values and no index if only one index exists or blockmode is on) |
0x02 | Request Data | requests specified data | no data |
0x03 | Enable Stream | request to get updates of specified data | no data |
0x04 | Disable Stream | request to stop geting updates of specified data | no data |
0x05 | Response Data | response of a data request | full dataset of given datatype |
0x06 | Stream Data | update notification of given datatype | full dataset of given datatype |
0x07 | Switch to 'Block' protocoll | switch to blockmode, datatype has to have the same value as validation | no data |
Datatypes:
Byte | Name | number of bytes |
---|---|---|
0x01 | Position | NUM_TRAINS = 11 |
0x02 | Destination | NUM_TRAINS = 11 |
0x03 | Cleanup | 1 |
0x04 | Randommode | 1 |
0x05 | Lamps | NUM_LAMPS = 24 |
0x06 | Schedule(actually Station) | NUM_TRAINS = 11 |
0x07 | Substation | NUM_TRAINS = 11 |
Running the WebProvider:
go into code/interface
run 'make web'
run './web'
Ideas for a new version:
- Don't use fixed datatypes, instead add a command to create a datatype by name and bytesize, which returns a datatypenumber, uniqe for each name, disconnects if size doesn't match with existing.
- Just use a different command to set the full dataset
- don't send updates to a client if the only change was caused by this client (just skip the current client on setting the dirty flag)
- Maybe add a minimum time between updates (prevents SSE and others from being flodded and the website actually crashing by a JavaScript DOS)