Response Types

With the exception of commands that terminate the session and close the TCP socket, every client request results in the M/Wire server returning a response.

There are three types of server responses:

Every response line is terminated by \r\n (CRLF).

Single-line Responses

The response is prefixed by a character that denotes its type:

An undefined value is denoted by a single-line response of $-1

Examples:

Client: PING\r\n
Server: +PONG\r\n

Client: SET myGlobal["a","b"] 3\r\n
Client: 123\r\n
Server: +OK\r\n

Client: EXISTS myGlobal["a","b"]\r\n
Server: :1\r\n

Client: GET myGlobal["a","b","c"]\r\n
Server: $-1\r\n

Client: XXX\r\n
Server: -XXX is not recognized\r\n

Two-line Responses

A two-line response consists of a first line that denotes the number of bytes that follow in the second line. The first line is prefixed with a dollar ($) character.

Examples:

Client: GET myGlobal["a","b"]\r\n
Server: $3\r\n
Server: 123\r\n

If the array contains a null ("") value, the response will be:

Client: GET myGlobal["a","b","c"]\r\n
Server: $0\r\n
Server: \r\n

Multi-line Responses

A multi-line response in structured as follows:

For example:

Client: GETSUBTREE myArray["1","2"]\r\n
Server: *6\r\n
Server: $7\r\n
Server: "a","b"\r\n
Server: $12\r\n
Server: Hello World!\r\n
Server: $7\r\n
Server: "a","c"\r\n
Server: $-1\r\n
Server: $11\r\n
Server: "a","b",123\r\n
Server: $6\r\n
Server: 123.45\r\n

In the example above, the *6 denotes that 6 records follow. The first consists of 7 bytes (denoted by the $7), the value of the record being "a","b".

Note that the fourth record is a null record, denoted by just a single line: $-1, so the next line ($11) defines the number of bytes in the fifth record.