Myth Network Protocol
The
MythTV backend process currently opens sockets for three different types of commands; a custom protocol (by default at port 6543), an HTML server (by default
http://127.0.0.1:6544 for the status, and other services under that, like < HREF="http://127.0.0.1:6544/Myth/GetMusic?Id=1">
http://127.0.0.1:6544/Myth/GetMusic?Id=1 ), and a UPnP media server (several ports that I cannot remember right now that throw around lots of little bits of XML :-)
The custom protocol is an ASCII encoded length and command string. Command sequences can be easily sent to the backend using telnet. e.g.
telnet 127.0.0.1 6543
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
21 MYTH_PROTO_VERSION 36 23 ANN Playback hostname 1 10 QUERY_LOAD 4DONE
13 ACCEPT[]:[]362 OK34 0.919922[]:[]0.908203[]:[]0.856445Connection closed by foreign host.
The command string is prefixed by 8 characters, containing the length of the forthcoming command. This can be justified in any way (as the above example shows)
The backend responds with a length, and the response to the command. This can be numbers (up to 32 bit, represented in ASCII), a single string, or an ASCII encoding of a QStringList. The 5 byte sequence "[]:[]" seperates items in the stringlist. Any 64 bit numbers are represented as a stringlist of two 32bit words (MSB first).
There are three main types of networking interactions in
MythTV; identification commands (which tell the backend about this client), query commands that are sent to the master backend (
e.g. listing recordings or viewing guide data), and file streaming commands (when a frontend is watching or editing a recording).
Until a client is identified to the backend (via the ANN commands), any of the query or file streaming commands will silently fail.
The following summarises some of these commands. For a full understanding of all the commands, either read the source code (programs/mythbackend/mainserver.cpp), or look on the Wiki (http://www.mythtv.org/wiki/index.php/Myth_Protocol_Command_List).
- MYTH_PROTO_VERSION version
- Checks that version matches the backend's version. If it matches, the stringlist of "ACCEPT" "version" is returned. If it does not, "REJECT" "version" is returned, and the socket is closed (for this client)
- ANN Playback host wantevents
- Register host as a client, and prevent shutdown of the socket.
- ANN Monitor host wantevents
- Register host as a client, and allow shutdown of the socket
- ANN SlaveBackend IPaddress
- ANN FileTransfer stringlist(hostname, filename)
- ANN FileTransfer stringlist(hostname, filename) useReadahead retries
- DONE
- Closes this client's socket.
- QUERY_FREE_SPACE
- Returns the free space on this backend, as a list of hostname, directory, 1, -1, total size, used (both in K and 64bit, so two 32bit numbers each).
- QUERY_FREE_SPACE_LIST
- Returns the free space on all hosts. (each host as above, except that the directory becomes a URL, and a TotalDiskSpace is appended)
- QUERY_FREE_SPACE_SUMMARY
- Summarises the free space on this backend, as list of total size, used
- QUERY_LOAD
- Returns the Unix load on this backend (three floats - the average over 1, 5 and 15 mins).
- QUERY_UPTIME
- Returns the number of seconds this backend's host has been running
- QUERY_MEMSTATS
- Returns total RAM, free RAM, total VM and free VM (all in MB)
- QUERY_CHECKFILE checkslaves programinfo