MythTV  master
MythTV 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/Status 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 :-) More...

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/Status 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 44 23     ANN Playback hostname 1   10   QUERY_LOAD       4DONE

13      ACCEPT[]:[]442       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 "[]:[]" separates items in the stringlist. Any 64 bit numbers are represented as a stringlist of two 32bit words (MSB first).

Commands

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/Category:Myth_Protocol_Commands).

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_HOSTNAME
Returns the hostname of this backend
QUERY_MEMSTATS
Returns total RAM, free RAM, total VM and free VM (all in MB)
QUERY_TIME_ZONE
Returns time zone ID, current offset, current time
QUERY_CHECKFILE filename recordinginfo
QUERY_FILE_EXISTS filename storagegroup
QUERY_FILE_HASH storagegroup filename
GET_PREVIEW <programinfo> token width height outputfile time time_fmt
PREVIEW_SUCCESS recordingId outFileName msg datetime token
PREVIEW_QUEUED recordingId outFileName msg datetime token
PREVIEW_FAILED recordingId outFileName msg datetime token
MYTH_PROTO_VERSION version token
Checks that version and token match 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 non-frontend client, and prevent shutdown of the socket.
ANN Frontend host wantevents
Register host as a Frontend client, and allow shutdown of the socket when idle
ANN Monitor host wantevents
Register host as a client, and allow shutdown of the socket
ANN SlaveBackend IPaddress
Register host as a slave backend, and allow shutdown of the socket
ANN MediaServer IPaddress
Register host as a media server
ANN FileTransfer stringlist(hostname, filename storageGroup)
ANN FileTransfer stringlist(hostname, filename storageGroup) writeMode
ANN FileTransfer stringlist(hostname, filename storageGroup) writeMode useReadahead
ANN FileTransfer stringlist(hostname, filename storageGroup) writeMode useReadahead retries
DONE
Closes this client's socket.
QUERY_RECORDINGS type
The type parameter can be either "Recording", "Unsorted", "Ascending", or "Descending". Returns programinfo (title, subtitle, description, category, chanid, channum, callsign, channel.name, fileURL, et cetera)
QUERY_RECORDING BASENAME basename
QUERY_RECORDING TIMESLOT chanid starttime
RESCHEDULE_RECORDINGS
Requests that all recordings after the current time be rescheduled.
GO_TO_SLEEP
Commands a slave to go to sleep
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_CHECKFILE checkslaves programinfo
MUSIC_LYRICS_GETGRABBERS
Get the names and version numbers of all scripts to grab music lyrics.