| 1 | Protocol |
|---|
| 2 | -------- |
|---|
| 3 | |
|---|
| 4 | Clients of memcached communicate with server through TCP connections. |
|---|
| 5 | (A UDP interface is also available; details are below under "UDP |
|---|
| 6 | protocol.") A given running memcached server listens on some |
|---|
| 7 | (configurable) port; clients connect to that port, send commands to |
|---|
| 8 | the server, read responses, and eventually close the connection. |
|---|
| 9 | |
|---|
| 10 | There is no need to send any command to end the session. A client may |
|---|
| 11 | just close the connection at any moment it no longer needs it. Note, |
|---|
| 12 | however, that clients are encouraged to cache their connections rather |
|---|
| 13 | than reopen them every time they need to store or retrieve data. This |
|---|
| 14 | is because memcached is especially designed to work very efficiently |
|---|
| 15 | with a very large number (many hundreds, more than a thousand if |
|---|
| 16 | necessary) of open connections. Caching connections will eliminate the |
|---|
| 17 | overhead associated with establishing a TCP connection (the overhead |
|---|
| 18 | of preparing for a new connection on the server side is insignificant |
|---|
| 19 | compared to this). |
|---|
| 20 | |
|---|
| 21 | There are two kinds of data sent in the memcache protocol: text lines |
|---|
| 22 | and unstructured data. Text lines are used for commands from clients |
|---|
| 23 | and responses from servers. Unstructured data is sent when a client |
|---|
| 24 | wants to store or retrieve data. The server will transmit back |
|---|
| 25 | unstructured data in exactly the same way it received it, as a byte |
|---|
| 26 | stream. The server doesn't care about byte order issues in |
|---|
| 27 | unstructured data and isn't aware of them. There are no limitations on |
|---|
| 28 | characters that may appear in unstructured data; however, the reader |
|---|
| 29 | of such data (either a client or a server) will always know, from a |
|---|
| 30 | preceding text line, the exact length of the data block being |
|---|
| 31 | transmitted. |
|---|
| 32 | |
|---|
| 33 | Text lines are always terminated by \r\n. Unstructured data is _also_ |
|---|
| 34 | terminated by \r\n, even though \r, \n or any other 8-bit characters |
|---|
| 35 | may also appear inside the data. Therefore, when a client retrieves |
|---|
| 36 | data from a server, it must use the length of the data block (which it |
|---|
| 37 | will be provided with) to determine where the data block ends, and not |
|---|
| 38 | the fact that \r\n follows the end of the data block, even though it |
|---|
| 39 | does. |
|---|
| 40 | |
|---|
| 41 | Keys |
|---|
| 42 | ---- |
|---|
| 43 | |
|---|
| 44 | Data stored by memcached is identified with the help of a key. A key |
|---|
| 45 | is a text string which should uniquely identify the data for clients |
|---|
| 46 | that are interested in storing and retrieving it. Currently the |
|---|
| 47 | length limit of a key is set at 250 characters (of course, normally |
|---|
| 48 | clients wouldn't need to use such long keys); the key must not include |
|---|
| 49 | control characters or whitespace. |
|---|
| 50 | |
|---|
| 51 | Commands |
|---|
| 52 | -------- |
|---|
| 53 | |
|---|
| 54 | There are three types of commands. |
|---|
| 55 | |
|---|
| 56 | Storage commands (there are four: "set", "add", "replace", and "cas") |
|---|
| 57 | ask the server to store some data identified by a key. The client |
|---|
| 58 | sends a command line, and then a data block; after that the client |
|---|
| 59 | expects one line of response, which will indicate success or faulure. |
|---|
| 60 | |
|---|
| 61 | Retrieval commands (there are two: "get" and "gets") ask the server to |
|---|
| 62 | retrieve data corresponding to a set of keys (one or more keys in one |
|---|
| 63 | request). The client sends a command line, which includes all the |
|---|
| 64 | requested keys; after that for each item the server finds it sends to |
|---|
| 65 | the client one response line with information about the item, and one |
|---|
| 66 | data block with the item's data; this continues until the server |
|---|
| 67 | finished with the "END" response line. |
|---|
| 68 | |
|---|
| 69 | All other commands don't involve unstructured data. In all of them, |
|---|
| 70 | the client sends one command line, and expects (depending on the |
|---|
| 71 | command) either one line of response, or several lines of response |
|---|
| 72 | ending with "END" on the last line. |
|---|
| 73 | |
|---|
| 74 | A command line always starts with the name of the command, followed by |
|---|
| 75 | parameters (if any) delimited by whitespace. Command names are |
|---|
| 76 | lower-case and are case-sensitive. |
|---|
| 77 | |
|---|
| 78 | Expiration times |
|---|
| 79 | ---------------- |
|---|
| 80 | |
|---|
| 81 | Some commands involve a client sending some kind of expiration time |
|---|
| 82 | (relative to an item or to an operation requested by the client) to |
|---|
| 83 | the server. In all such cases, the actual value sent may either be |
|---|
| 84 | Unix time (number of seconds since January 1, 1970, as a 32-bit |
|---|
| 85 | value), or a number of seconds starting from current time. In the |
|---|
| 86 | latter case, this number of seconds may not exceed 60*60*24*30 (number |
|---|
| 87 | of seconds in 30 days); if the number sent by a client is larger than |
|---|
| 88 | that, the server will consider it to be real Unix time value rather |
|---|
| 89 | than an offset from current time. |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | Error strings |
|---|
| 93 | ------------- |
|---|
| 94 | |
|---|
| 95 | Each command sent by a client may be answered with an error string |
|---|
| 96 | from the server. These error strings come in three types: |
|---|
| 97 | |
|---|
| 98 | - "ERROR\r\n" |
|---|
| 99 | |
|---|
| 100 | means the client sent a nonexistent command name. |
|---|
| 101 | |
|---|
| 102 | - "CLIENT_ERROR <error>\r\n" |
|---|
| 103 | |
|---|
| 104 | means some sort of client error in the input line, i.e. the input |
|---|
| 105 | doesn't conform to the protocol in some way. <error> is a |
|---|
| 106 | human-readable error string. |
|---|
| 107 | |
|---|
| 108 | - "SERVER_ERROR <error>\r\n" |
|---|
| 109 | |
|---|
| 110 | means some sort of server error prevents the server from carrying |
|---|
| 111 | out the command. <error> is a human-readable error string. In cases |
|---|
| 112 | of severe server errors, which make it impossible to continue |
|---|
| 113 | serving the client (this shouldn't normally happen), the server will |
|---|
| 114 | close the connection after sending the error line. This is the only |
|---|
| 115 | case in which the server closes a connection to a client. |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | In the descriptions of individual commands below, these error lines |
|---|
| 119 | are not again specifically mentioned, but clients must allow for their |
|---|
| 120 | possibility. |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | Storage commands |
|---|
| 124 | ---------------- |
|---|
| 125 | |
|---|
| 126 | First, the client sends a command line which looks like this: |
|---|
| 127 | |
|---|
| 128 | <command name> <key> <flags> <exptime> <bytes> [<unqiue>]\r\n |
|---|
| 129 | |
|---|
| 130 | - <command name> is "set", "add", "replace", or "cas" |
|---|
| 131 | |
|---|
| 132 | "set" means "store this data". |
|---|
| 133 | |
|---|
| 134 | "add" means "store this data, but only if the server *doesn't* already |
|---|
| 135 | hold data for this key". |
|---|
| 136 | |
|---|
| 137 | "replace" means "store this data, but only if the server *does* |
|---|
| 138 | already hold data for this key". |
|---|
| 139 | |
|---|
| 140 | "cas" is a check and set operation which means "store this data but |
|---|
| 141 | only if no one else has updated since I last fetched it." |
|---|
| 142 | |
|---|
| 143 | - <key> is the key under which the client asks to store the data |
|---|
| 144 | |
|---|
| 145 | - <flags> is an arbitrary 16-bit unsigned integer (written out in |
|---|
| 146 | decimal) that the server stores along with the data and sends back |
|---|
| 147 | when the item is retrieved. Clients may use this as a bit field to |
|---|
| 148 | store data-specific information; this field is opaque to the server. |
|---|
| 149 | Note that in memcached 1.2.1 and higher, flags may be 32-bits, instead |
|---|
| 150 | of 16, but you might want to restrict yourself to 16 bits for |
|---|
| 151 | compatibility with older versions. |
|---|
| 152 | |
|---|
| 153 | - <exptime> is expiration time. If it's 0, the item never expires |
|---|
| 154 | (although it may be deleted from the cache to make place for other |
|---|
| 155 | items). If it's non-zero (either Unix time or offset in seconds from |
|---|
| 156 | current time), it is guaranteed that clients will not be able to |
|---|
| 157 | retrieve this item after the expiration time arrives (measured by |
|---|
| 158 | server time). |
|---|
| 159 | |
|---|
| 160 | - <bytes> is the number of bytes in the data block to follow, *not* |
|---|
| 161 | including the delimiting \r\n. <bytes> may be zero (in which case |
|---|
| 162 | it's followed by an empty data block). |
|---|
| 163 | |
|---|
| 164 | - <cas unique> is a unique 64-bit value of an existing entry. |
|---|
| 165 | |
|---|
| 166 | After this line, the client sends the data block: |
|---|
| 167 | |
|---|
| 168 | <data block>\r\n |
|---|
| 169 | |
|---|
| 170 | - <data block> is a chunk of arbitrary 8-bit data of length <bytes> |
|---|
| 171 | from the previous line. |
|---|
| 172 | |
|---|
| 173 | After sending the command line and the data blockm the client awaits |
|---|
| 174 | the reply, which may be: |
|---|
| 175 | |
|---|
| 176 | - "STORED\r\n", to indicate success. |
|---|
| 177 | |
|---|
| 178 | - "NOT_STORED\r\n" to indicate the data was not stored, but not |
|---|
| 179 | because of an error. This normally means that either that the |
|---|
| 180 | condition for an "add" or a "replace" command wasn't met, or that the |
|---|
| 181 | item is in a delete queue (see the "delete" command below). |
|---|
| 182 | |
|---|
| 183 | - "EXISTS\r\n" to indicate that the item you are trying to store with |
|---|
| 184 | a "cas" command has been modified since you last fetched it. |
|---|
| 185 | |
|---|
| 186 | Retrieval command: |
|---|
| 187 | ------------------ |
|---|
| 188 | |
|---|
| 189 | The retrieval commands "get" and "gets" operates like this: |
|---|
| 190 | |
|---|
| 191 | get <key>*\r\n |
|---|
| 192 | gets <key>*\r\n |
|---|
| 193 | |
|---|
| 194 | - <key>* means one or more key strings separated by whitespace. |
|---|
| 195 | |
|---|
| 196 | After this command, the client expects zero or more items, each of |
|---|
| 197 | which is received as a text line followed by a data block. After all |
|---|
| 198 | the items have been transmitted, the server sends the string |
|---|
| 199 | |
|---|
| 200 | "END\r\n" |
|---|
| 201 | |
|---|
| 202 | to indicate the end of response. |
|---|
| 203 | |
|---|
| 204 | Each item sent by the server looks like this: |
|---|
| 205 | |
|---|
| 206 | VALUE <key> <flags> <bytes> [<cas unique>]\r\n |
|---|
| 207 | <data block>\r\n |
|---|
| 208 | |
|---|
| 209 | - <key> is the key for the item being sent |
|---|
| 210 | |
|---|
| 211 | - <flags> is the flags value set by the storage command |
|---|
| 212 | |
|---|
| 213 | - <bytes> is the length of the data block to follow, *not* including |
|---|
| 214 | its delimiting \r\n |
|---|
| 215 | |
|---|
| 216 | - <cas unique> is a unique 64-bit integer that uniquely identifies |
|---|
| 217 | this specific item. |
|---|
| 218 | |
|---|
| 219 | - <data block> is the data for this item. |
|---|
| 220 | |
|---|
| 221 | If some of the keys appearing in a retrieval request are not sent back |
|---|
| 222 | by the server in the item list this means that the server does not |
|---|
| 223 | hold items with such keys (because they were never stored, or stored |
|---|
| 224 | but deleted to make space for more items, or expired, or explicitly |
|---|
| 225 | deleted by a client). |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | Deletion |
|---|
| 229 | -------- |
|---|
| 230 | |
|---|
| 231 | The command "delete" allows for explicit deletion of items: |
|---|
| 232 | |
|---|
| 233 | delete <key> <time>\r\n |
|---|
| 234 | |
|---|
| 235 | - <key> is the key of the item the client wishes the server to delete |
|---|
| 236 | |
|---|
| 237 | - <time> is the amount of time in seconds (or Unix time until which) |
|---|
| 238 | the client wishes the server to refuse "add" and "replace" commands |
|---|
| 239 | with this key. For this amount of item, the item is put into a |
|---|
| 240 | delete queue, which means that it won't possible to retrieve it by |
|---|
| 241 | the "get" command, but "add" and "replace" command with this key |
|---|
| 242 | will also fail (the "set" command will succeed, however). After the |
|---|
| 243 | time passes, the item is finally deleted from server memory. |
|---|
| 244 | |
|---|
| 245 | The parameter <time> is optional, and, if absent, defaults to 0 |
|---|
| 246 | (which means that the item will be deleted immediately and further |
|---|
| 247 | storage commands with this key will succeed). |
|---|
| 248 | |
|---|
| 249 | The response line to this command can be one of: |
|---|
| 250 | |
|---|
| 251 | - "DELETED\r\n" to indicate success |
|---|
| 252 | |
|---|
| 253 | - "NOT_FOUND\r\n" to indicate that the item with this key was not |
|---|
| 254 | found. |
|---|
| 255 | |
|---|
| 256 | See the "flush_all" command below for immediate invalidation |
|---|
| 257 | of all existing items. |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | Increment/Decrement |
|---|
| 261 | ------------------- |
|---|
| 262 | |
|---|
| 263 | Commands "incr" and "decr" are used to change data for some item |
|---|
| 264 | in-place, incrementing or decrementing it. The data for the item is |
|---|
| 265 | treated as decimal representation of a 32-bit unsigned integer. If the |
|---|
| 266 | current data value does not conform to such a representation, the |
|---|
| 267 | commands behave as if the value were 0. Also, the item must already |
|---|
| 268 | exist for incr/decr to work; these commands won't pretend that a |
|---|
| 269 | non-existent key exists with value 0; instead, they will fail. |
|---|
| 270 | |
|---|
| 271 | The client sends the command line: |
|---|
| 272 | |
|---|
| 273 | incr <key> <value>\r\n |
|---|
| 274 | |
|---|
| 275 | or |
|---|
| 276 | |
|---|
| 277 | decr <key> <value>\r\n |
|---|
| 278 | |
|---|
| 279 | - <key> is the key of the item the client wishes to change |
|---|
| 280 | |
|---|
| 281 | - <value> is the amount by which the client wants to increase/decrease |
|---|
| 282 | the item. It is a decimal representation of a 32-bit unsigned integer. |
|---|
| 283 | |
|---|
| 284 | The response will be one of: |
|---|
| 285 | |
|---|
| 286 | - "NOT_FOUND\r\n" to indicate the item with this value was not found |
|---|
| 287 | |
|---|
| 288 | - <value>\r\n , where <value> is the new value of the item's data, |
|---|
| 289 | after the increment/decrement operation was carried out. |
|---|
| 290 | |
|---|
| 291 | Note that underflow in the "decr" command is caught: if a client tries |
|---|
| 292 | to decrease the value below 0, the new value will be 0. Overflow in the |
|---|
| 293 | "incr" command will wrap around the 32 bit mark. |
|---|
| 294 | |
|---|
| 295 | Note also that decrementing a number such that it loses length isn't |
|---|
| 296 | guaranteed to decrement its returned length. The number MAY be |
|---|
| 297 | space-padded at the end, but this is purely an implementation |
|---|
| 298 | optimization, so you also shouldn't rely on that. |
|---|
| 299 | |
|---|
| 300 | Statistics |
|---|
| 301 | ---------- |
|---|
| 302 | |
|---|
| 303 | The command "stats" is used to query the server about statistics it |
|---|
| 304 | maintains and other internal data. It has two forms. Without |
|---|
| 305 | arguments: |
|---|
| 306 | |
|---|
| 307 | stats\r\n |
|---|
| 308 | |
|---|
| 309 | it causes the server to output general-purpose statistics and |
|---|
| 310 | settings, documented below. In the other form it has some arguments: |
|---|
| 311 | |
|---|
| 312 | stats <args>\r\n |
|---|
| 313 | |
|---|
| 314 | Depending on <args>, various internal data is sent by the server. The |
|---|
| 315 | kinds of arguments and the data sent are not documented in this vesion |
|---|
| 316 | of the protocol, and are subject to change for the convenience of |
|---|
| 317 | memcache developers. |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | General-purpose statistics |
|---|
| 321 | -------------------------- |
|---|
| 322 | |
|---|
| 323 | Upon receiving the "stats" command without arguments, the server sents |
|---|
| 324 | a number of lines which look like this: |
|---|
| 325 | |
|---|
| 326 | STAT <name> <value>\r\n |
|---|
| 327 | |
|---|
| 328 | The server terminates this list with the line |
|---|
| 329 | |
|---|
| 330 | END\r\n |
|---|
| 331 | |
|---|
| 332 | In each line of statistics, <name> is the name of this statistic, and |
|---|
| 333 | <value> is the data. The following is the list of all names sent in |
|---|
| 334 | response to the "stats" command, together with the type of the value |
|---|
| 335 | sent for this name, and the meaning of the value. |
|---|
| 336 | |
|---|
| 337 | In the type column below, "32u" means a 32-bit unsigned integer, "64u" |
|---|
| 338 | means a 64-bit unsigner integer. '32u:32u' means two 32-but unsigned |
|---|
| 339 | integers separated by a colon. |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | Name Type Meaning |
|---|
| 343 | ---------------------------------- |
|---|
| 344 | pid 32u Process id of this server process |
|---|
| 345 | uptime 32u Number of seconds this server has been running |
|---|
| 346 | time 32u current UNIX time according to the server |
|---|
| 347 | version string Version string of this server |
|---|
| 348 | pointer_size 32 Default size of pointers on the host OS |
|---|
| 349 | (generally 32 or 64) |
|---|
| 350 | rusage_user 32u:32u Accumulated user time for this process |
|---|
| 351 | (seconds:microseconds) |
|---|
| 352 | rusage_system 32u:32u Accumulated system time for this process |
|---|
| 353 | (seconds:microseconds) |
|---|
| 354 | curr_items 32u Current number of items stored by the server |
|---|
| 355 | total_items 32u Total number of items stored by this server |
|---|
| 356 | ever since it started |
|---|
| 357 | bytes 64u Current number of bytes used by this server |
|---|
| 358 | to store items |
|---|
| 359 | curr_connections 32u Number of open connections |
|---|
| 360 | total_connections 32u Total number of connections opened since |
|---|
| 361 | the server started running |
|---|
| 362 | connection_structures 32u Number of connection structures allocated |
|---|
| 363 | by the server |
|---|
| 364 | cmd_get 64u Cumulative number of retrieval requests |
|---|
| 365 | cmd_set 64u Cumulative number of storage requests |
|---|
| 366 | get_hits 64u Number of keys that have been requested and |
|---|
| 367 | found present |
|---|
| 368 | get_misses 64u Number of items that have been requested |
|---|
| 369 | and not found |
|---|
| 370 | evictions 64u Number of valid items removed from cache |
|---|
| 371 | to free memory for new items |
|---|
| 372 | bytes_read 64u Total number of bytes read by this server |
|---|
| 373 | from network |
|---|
| 374 | bytes_written 64u Total number of bytes sent by this server to |
|---|
| 375 | network |
|---|
| 376 | limit_maxbytes 32u Number of bytes this server is allowed to |
|---|
| 377 | use for storage. |
|---|
| 378 | threads 32u Number of worker threads requested. |
|---|
| 379 | (see doc/threads.txt) |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | Other commands |
|---|
| 384 | -------------- |
|---|
| 385 | |
|---|
| 386 | "flush_all" is a command with an optional numeric argument. It always |
|---|
| 387 | succeeds, and the server sends "OK\r\n" in response. Its effect is to |
|---|
| 388 | invalidate all existing items immediately (by default) or after the |
|---|
| 389 | expiration specified. After invalidation none of the items will be returned |
|---|
| 390 | in response to a retrieval command (unless it's stored again under the |
|---|
| 391 | same key *after* flush_all has invalidated the items). flush_all doesn't |
|---|
| 392 | actually free all the memory taken up by existing items; that will |
|---|
| 393 | happen gradually as new items are stored. The most precise definition |
|---|
| 394 | of what flush_all does is the following: it causes all items whose |
|---|
| 395 | update time is earlier than the time at which flush_all was set to be |
|---|
| 396 | executed to be ignored for retrieval purposes. |
|---|
| 397 | |
|---|
| 398 | The intent of flush_all with a delay, was that in a setting where you |
|---|
| 399 | have a pool of memcached servers, and you need to flush all content, |
|---|
| 400 | you have the option of not resetting all memcached servers at the |
|---|
| 401 | same time (which could e.g. cause a spike in database load with all |
|---|
| 402 | clients suddenly needing to recreate content that would otherwise |
|---|
| 403 | have been found in the memcached daemon). |
|---|
| 404 | |
|---|
| 405 | The delay option allows you to have them reset in e.g. 10 second |
|---|
| 406 | intervals (by passing 0 to the first, 10 to the second, 20 to the |
|---|
| 407 | third, etc. etc.). |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | "version" is a command with no arguments: |
|---|
| 411 | |
|---|
| 412 | version\r\n |
|---|
| 413 | |
|---|
| 414 | In response, the server sends |
|---|
| 415 | |
|---|
| 416 | "VERSION <version>\r\n", where <version> is the version string for the |
|---|
| 417 | server. |
|---|
| 418 | |
|---|
| 419 | "verbosity" is a command with a numeric argument. It always |
|---|
| 420 | succeeds, and the server sends "OK\r\n" in response. Its effect is to |
|---|
| 421 | set the verbosity level of the logging output. |
|---|
| 422 | |
|---|
| 423 | "quit" is a command with no arguments: |
|---|
| 424 | |
|---|
| 425 | quit\r\n |
|---|
| 426 | |
|---|
| 427 | Upon receiving this command, the server closes the |
|---|
| 428 | connection. However, the client may also simply close the connection |
|---|
| 429 | when it no longer needs it, without issuing this command. |
|---|
| 430 | |
|---|
| 431 | |
|---|
| 432 | UDP protocol |
|---|
| 433 | ------------ |
|---|
| 434 | |
|---|
| 435 | For very large installations where the number of clients is high enough |
|---|
| 436 | that the number of TCP connections causes scaling difficulties, there is |
|---|
| 437 | also a UDP-based interface. The UDP interface does not provide guaranteed |
|---|
| 438 | delivery, so should only be used for operations that aren't required to |
|---|
| 439 | succeed; typically it is used for "get" requests where a missing or |
|---|
| 440 | incomplete response can simply be treated as a cache miss. |
|---|
| 441 | |
|---|
| 442 | Each UDP datagram contains a simple frame header, followed by data in the |
|---|
| 443 | same format as the TCP protocol described above. In the current |
|---|
| 444 | implementation, requests must be contained in a single UDP datagram, but |
|---|
| 445 | responses may span several datagrams. (The only common requests that would |
|---|
| 446 | span multiple datagrams are huge multi-key "get" requests and "set" |
|---|
| 447 | requests, both of which are more suitable to TCP transport for reliability |
|---|
| 448 | reasons anyway.) |
|---|
| 449 | |
|---|
| 450 | The frame header is 8 bytes long, as follows (all values are 16-bit integers |
|---|
| 451 | in network byte order, high byte first): |
|---|
| 452 | |
|---|
| 453 | 0-1 Request ID |
|---|
| 454 | 2-3 Sequence number |
|---|
| 455 | 4-5 Total number of datagrams in this message |
|---|
| 456 | 6-7 Reserved for future use; must be 0 |
|---|
| 457 | |
|---|
| 458 | The request ID is supplied by the client. Typically it will be a |
|---|
| 459 | monotonically increasing value starting from a random seed, but the client |
|---|
| 460 | is free to use whatever request IDs it likes. The server's response will |
|---|
| 461 | contain the same ID as the incoming request. The client uses the request ID |
|---|
| 462 | to differentiate between responses to outstanding requests if there are |
|---|
| 463 | several pending from the same server; any datagrams with an unknown request |
|---|
| 464 | ID are probably delayed responses to an earlier request and should be |
|---|
| 465 | discarded. |
|---|
| 466 | |
|---|
| 467 | The sequence number ranges from 0 to n-1, where n is the total number of |
|---|
| 468 | datagrams in the message. The client should concatenate the payloads of the |
|---|
| 469 | datagrams for a given response in sequence number order; the resulting byte |
|---|
| 470 | stream will contain a complete response in the same format as the TCP |
|---|
| 471 | protocol (including terminating \r\n sequences). |
|---|