User:Narc/Extensible Messaging Protocol

Note to self: this thing needs a decent name.

Commands
Commands may be sent by either server or client. Commands are case-insensitive. All commands are of one of these forms: command command: single argument, which may be a comma-separated list command: first argument; second argument; ...

Arguments are optional (commands may have no arguments), and if not present, the colon separator can also be omitted. Arguments are case-insensitive unless otherwise mentioned in the command description. Multiple commands in the same message must be separated by \n (the line feed character, also known as a newline (ASCII character #10)).

If there are multiple arguments, semicolons (ASCII character #59) must be used to separate them from each other.

Arguments may be lists, in which case commas (ASCII character #44) must be used to separate the list elements.

Whitespace is not significant except when in the middle of a command, argument, or list item (i.e. whitespace around punctuation is ignored -- "command: arg" and "command:arg" are the same thing).

Commas, semicolons, newlines and ampersands (ASCII character #38) inside arguments must be escaped as HTML entities:
 * commas become &amp;#44;
 * semicolons become &amp;#59;
 * newlines become &amp;#10;
 * ampersands become &amp;amp;

Other HTML entities may be used as desired, and must be understood by the receiving host (server or client).

Unknown commands must be ignored. Capabilities should be used to determine what commands the remote host can understand.

Base Protocol and Implementation
At its core, the protocol is for communicating between a server and one or more (usually more) clients, with a very small number of required capabilities.

Required Capabilities

 * nicknames (client only) -- before interacting with any other clients, clients must first "log in" to the server by specifying a nickname. Clients may remain nickname-less to interact with the server, if the server has any nickname-less capabilities.
 * capability capability (client and server) -- clients must be able to send their own capabilities when requested, and must be able to understand the server's capabilities. Clients without this capability will be disconnected automatically after 30 seconds. This capability is required to allow any interaction with the server.
 * ask capability (client and server) -- clients and servers must be able to ask each other for various bits of information, which must be implemented as the "what" command, with "tell" used to respond unless a different command (like capa) would be more appropriate.

Required Commands
Required commands for this implementation level:

Askable information
Questions may be sent by either server or client unless otherwise specified. Responses are in the form of a tell command unless otherwise specified.


 * what: ip -- Remote must respond with the IP it believes it is connected to (i.e. server will respond with client's IP, client with server's IP).
 * what: capa -- Remote must respond with a capa command containing its capabilities.
 * what: connection time -- Remote must respond with the time elapsed since initial connection, in seconds.

Example session
In this example, the client was lazy and waited to receive and process Hello from from the server before saying anything. It could have also immediately sent the capa command, or all three commands with \n between them all at once. Likewise the server, when responding to the what command could have responded with both tell and capa in one message, \n-separated.