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.
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
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
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
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.
54
There are three types of commands.
56
Storage commands (there are six: "set", "add", "replace", "append"
57
"prepend" and "cas") ask the server to store some data identified by a
58
key. The client sends a command line, and then a data block; after
59
that the client expects one line of response, which will indicate
62
Retrieval commands (there are two: "get" and "gets") ask the server to
63
retrieve data corresponding to a set of keys (one or more keys in one
64
request). The client sends a command line, which includes all the
65
requested keys; after that for each item the server finds it sends to
66
the client one response line with information about the item, and one
67
data block with the item's data; this continues until the server
68
finished with the "END" response line.
70
All other commands don't involve unstructured data. In all of them,
71
the client sends one command line, and expects (depending on the
72
command) either one line of response, or several lines of response
73
ending with "END" on the last line.
75
A command line always starts with the name of the command, followed by
76
parameters (if any) delimited by whitespace. Command names are
77
lower-case and are case-sensitive.
82
Some commands involve a client sending some kind of expiration time
83
(relative to an item or to an operation requested by the client) to
84
the server. In all such cases, the actual value sent may either be
85
Unix time (number of seconds since January 1, 1970, as a 32-bit
86
value), or a number of seconds starting from current time. In the
87
latter case, this number of seconds may not exceed 60*60*24*30 (number
88
of seconds in 30 days); if the number sent by a client is larger than
89
that, the server will consider it to be real Unix time value rather
90
than an offset from current time.
96
Each command sent by a client may be answered with an error string
97
from the server. These error strings come in three types:
101
means the client sent a nonexistent command name.
103
- "CLIENT_ERROR <error>\r\n"
105
means some sort of client error in the input line, i.e. the input
106
doesn't conform to the protocol in some way. <error> is a
107
human-readable error string.
109
- "SERVER_ERROR <error>\r\n"
111
means some sort of server error prevents the server from carrying
112
out the command. <error> is a human-readable error string. In cases
113
of severe server errors, which make it impossible to continue
114
serving the client (this shouldn't normally happen), the server will
115
close the connection after sending the error line. This is the only
116
case in which the server closes a connection to a client.
119
In the descriptions of individual commands below, these error lines
120
are not again specifically mentioned, but clients must allow for their
127
First, the client sends a command line which looks like this:
129
<command name> <key> <flags> <exptime> <bytes> [noreply]\r\n
130
cas <key> <flags> <exptime> <bytes> <cas unique> [noreply]\r\n
132
- <command name> is "set", "add", "replace", "append" or "prepend"
134
"set" means "store this data".
136
"add" means "store this data, but only if the server *doesn't* already
137
hold data for this key".
139
"replace" means "store this data, but only if the server *does*
140
already hold data for this key".
142
"append" means "add this data to an existing key after existing data".
144
"prepend" means "add this data to an existing key before existing data".
146
The append and prepend commands do not accept flags or exptime.
147
They update existing data portions, and ignore new flag and exptime
150
"cas" is a check and set operation which means "store this data but
151
only if no one else has updated since I last fetched it."
153
- <key> is the key under which the client asks to store the data
155
- <flags> is an arbitrary 16-bit unsigned integer (written out in
156
decimal) that the server stores along with the data and sends back
157
when the item is retrieved. Clients may use this as a bit field to
158
store data-specific information; this field is opaque to the server.
159
Note that in memcached 1.2.1 and higher, flags may be 32-bits, instead
160
of 16, but you might want to restrict yourself to 16 bits for
161
compatibility with older versions.
163
- <exptime> is expiration time. If it's 0, the item never expires
164
(although it may be deleted from the cache to make place for other
165
items). If it's non-zero (either Unix time or offset in seconds from
166
current time), it is guaranteed that clients will not be able to
167
retrieve this item after the expiration time arrives (measured by
170
- <bytes> is the number of bytes in the data block to follow, *not*
171
including the delimiting \r\n. <bytes> may be zero (in which case
172
it's followed by an empty data block).
174
- <cas unique> is a unique 64-bit value of an existing entry.
175
Clients should use the value returned from the "gets" command
176
when issuing "cas" updates.
178
- "noreply" optional parameter instructs the server to not send the
179
reply. NOTE: if the request line is malformed, the server can't
180
parse "noreply" option reliably. In this case it may send the error
181
to the client, and not reading it on the client side will break
182
things. Client should construct only valid requests.
184
After this line, the client sends the data block:
188
- <data block> is a chunk of arbitrary 8-bit data of length <bytes>
189
from the previous line.
191
After sending the command line and the data blockm the client awaits
192
the reply, which may be:
194
- "STORED\r\n", to indicate success.
196
- "NOT_STORED\r\n" to indicate the data was not stored, but not
197
because of an error. This normally means that the
198
condition for an "add" or a "replace" command wasn't met.
200
- "EXISTS\r\n" to indicate that the item you are trying to store with
201
a "cas" command has been modified since you last fetched it.
203
- "NOT_FOUND\r\n" to indicate that the item you are trying to store
204
with a "cas" command did not exist.
210
The retrieval commands "get" and "gets" operates like this:
215
- <key>* means one or more key strings separated by whitespace.
217
After this command, the client expects zero or more items, each of
218
which is received as a text line followed by a data block. After all
219
the items have been transmitted, the server sends the string
223
to indicate the end of response.
225
Each item sent by the server looks like this:
227
VALUE <key> <flags> <bytes> [<cas unique>]\r\n
230
- <key> is the key for the item being sent
232
- <flags> is the flags value set by the storage command
234
- <bytes> is the length of the data block to follow, *not* including
237
- <cas unique> is a unique 64-bit integer that uniquely identifies
240
- <data block> is the data for this item.
242
If some of the keys appearing in a retrieval request are not sent back
243
by the server in the item list this means that the server does not
244
hold items with such keys (because they were never stored, or stored
245
but deleted to make space for more items, or expired, or explicitly
246
deleted by a client).
252
The command "delete" allows for explicit deletion of items:
254
delete <key> [noreply]\r\n
256
- <key> is the key of the item the client wishes the server to delete
258
- "noreply" optional parameter instructs the server to not send the
259
reply. See the note in Storage commands regarding malformed
262
The response line to this command can be one of:
264
- "DELETED\r\n" to indicate success
266
- "NOT_FOUND\r\n" to indicate that the item with this key was not
269
See the "flush_all" command below for immediate invalidation
270
of all existing items.
276
Commands "incr" and "decr" are used to change data for some item
277
in-place, incrementing or decrementing it. The data for the item is
278
treated as decimal representation of a 64-bit unsigned integer. If
279
the current data value does not conform to such a representation, the
280
incr/decr commands return an error (memcached <= 1.2.6 treated the
281
bogus value as if it were 0, leading to confusing). Also, the item
282
must already exist for incr/decr to work; these commands won't pretend
283
that a non-existent key exists with value 0; instead, they will fail.
285
The client sends the command line:
287
incr <key> <value> [noreply]\r\n
291
decr <key> <value> [noreply]\r\n
293
- <key> is the key of the item the client wishes to change
295
- <value> is the amount by which the client wants to increase/decrease
296
the item. It is a decimal representation of a 64-bit unsigned integer.
298
- "noreply" optional parameter instructs the server to not send the
299
reply. See the note in Storage commands regarding malformed
302
The response will be one of:
304
- "NOT_FOUND\r\n" to indicate the item with this value was not found
306
- <value>\r\n , where <value> is the new value of the item's data,
307
after the increment/decrement operation was carried out.
309
Note that underflow in the "decr" command is caught: if a client tries
310
to decrease the value below 0, the new value will be 0. Overflow in
311
the "incr" command will wrap around the 64 bit mark.
313
Note also that decrementing a number such that it loses length isn't
314
guaranteed to decrement its returned length. The number MAY be
315
space-padded at the end, but this is purely an implementation
316
optimization, so you also shouldn't rely on that.
321
The "touch" command is used to update the expiration time of an existing item
324
touch <key> <exptime> [noreply]\r\n
326
- <key> is the key of the item the client wishes the server to delete
328
- <exptime> is expiration time. Works the same as with the update commands
329
(set/add/etc). This replaces the existing expiration time. If an existing
330
item were to expire in 10 seconds, but then was touched with an
331
expiration time of "20", the item would then expire in 20 seconds.
333
- "noreply" optional parameter instructs the server to not send the
334
reply. See the note in Storage commands regarding malformed
337
The response line to this command can be one of:
339
- "TOUCHED\r\n" to indicate success
341
- "NOT_FOUND\r\n" to indicate that the item with this key was not
347
NOTE: This command is subject to change as of this writing.
349
The slabs reassign command is used to redistribute memory once a running
350
instance has hit its limit. It might be desireable to have memory laid out
351
differently than was automatically assigned after the server started.
353
slabs reassign <source class> <dest class>\r\n
355
- <source class> is an id number for the slab class to steal a page from
357
- <dest class> is an id number for the slab class to move a page to
359
The response line could be one of:
361
- "OK" to indicate the page has been scheduled to move
363
- "BUSY [message]" to indicate a page is already being processed, try again
366
- "BADCLASS [message]" a bad class id was specified
368
- "NOSPARE [message]" source class has no spare pages
370
- "NOTFULL [message]" dest class must be full to move new pages to it
372
- "UNSAFE [message]" source class cannot move a page right now
374
- "SAME [message]" must specify different source/dest ids.
379
NOTE: This command is subject to change as of this writing.
381
The slabs automove command enables a background thread which decides on its
382
own when to move memory between slab classes. Its implementation and options
383
will likely be in flux for several versions. See the wiki/mailing list for
386
The automover can be enabled or disabled at runtime with this command.
390
- 1|0 is the indicator on whether to enable the slabs automover or not.
392
The response should always be "OK\r\n"
397
The command "stats" is used to query the server about statistics it
398
maintains and other internal data. It has two forms. Without
403
it causes the server to output general-purpose statistics and
404
settings, documented below. In the other form it has some arguments:
408
Depending on <args>, various internal data is sent by the server. The
409
kinds of arguments and the data sent are not documented in this vesion
410
of the protocol, and are subject to change for the convenience of
414
General-purpose statistics
415
--------------------------
417
Upon receiving the "stats" command without arguments, the server sents
418
a number of lines which look like this:
420
STAT <name> <value>\r\n
422
The server terminates this list with the line
426
In each line of statistics, <name> is the name of this statistic, and
427
<value> is the data. The following is the list of all names sent in
428
response to the "stats" command, together with the type of the value
429
sent for this name, and the meaning of the value.
431
In the type column below, "32u" means a 32-bit unsigned integer, "64u"
432
means a 64-bit unsigned integer. '32u.32u' means two 32-bit unsigned
433
integers separated by a colon (treat this as a floating point number).
435
|-----------------------+---------+-------------------------------------------|
436
| Name | Type | Meaning |
437
|-----------------------+---------+-------------------------------------------|
438
| pid | 32u | Process id of this server process |
439
| uptime | 32u | Number of secs since the server started |
440
| time | 32u | current UNIX time according to the server |
441
| version | string | Version string of this server |
442
| pointer_size | 32 | Default size of pointers on the host OS |
443
| | | (generally 32 or 64) |
444
| rusage_user | 32u.32u | Accumulated user time for this process |
445
| | | (seconds:microseconds) |
446
| rusage_system | 32u.32u | Accumulated system time for this process |
447
| | | (seconds:microseconds) |
448
| curr_items | 32u | Current number of items stored |
449
| total_items | 32u | Total number of items stored since |
450
| | | the server started |
451
| bytes | 64u | Current number of bytes used |
452
| | | to store items |
453
| curr_connections | 32u | Number of open connections |
454
| total_connections | 32u | Total number of connections opened since |
455
| | | the server started running |
456
| connection_structures | 32u | Number of connection structures allocated |
457
| | | by the server |
458
| reserved_fds | 32u | Number of misc fds used internally |
459
| cmd_get | 64u | Cumulative number of retrieval reqs |
460
| cmd_set | 64u | Cumulative number of storage reqs |
461
| cmd_flush | 64u | Cumulative number of flush reqs |
462
| cmd_touch | 64u | Cumulative number of touch reqs |
463
| get_hits | 64u | Number of keys that have been requested |
464
| | | and found present |
465
| get_misses | 64u | Number of items that have been requested |
466
| | | and not found |
467
| delete_misses | 64u | Number of deletions reqs for missing keys |
468
| delete_hits | 64u | Number of deletion reqs resulting in |
469
| | | an item being removed. |
470
| incr_misses | 64u | Number of incr reqs against missing keys. |
471
| incr_hits | 64u | Number of successful incr reqs. |
472
| decr_misses | 64u | Number of decr reqs against missing keys. |
473
| decr_hits | 64u | Number of successful decr reqs. |
474
| cas_misses | 64u | Number of CAS reqs against missing keys. |
475
| cas_hits | 64u | Number of successful CAS reqs. |
476
| cas_badval | 64u | Number of CAS reqs for which a key was |
477
| | | found, but the CAS value did not match. |
478
| touch_hits | 64u | Numer of keys that have been touched with |
479
| | | a new expiration time |
480
| touch_misses | 64u | Numer of items that have been touched and |
482
| auth_cmds | 64u | Number of authentication commands |
483
| | | handled, success or failure. |
484
| auth_errors | 64u | Number of failed authentications. |
485
| evictions | 64u | Number of valid items removed from cache |
486
| | | to free memory for new items |
487
| reclaimed | 64u | Number of times an entry was stored using |
488
| | | memory from an expired entry |
489
| bytes_read | 64u | Total number of bytes read by this server |
491
| bytes_written | 64u | Total number of bytes sent by this server |
493
| limit_maxbytes | 32u | Number of bytes this server is allowed to |
494
| | | use for storage. |
495
| threads | 32u | Number of worker threads requested. |
496
| | | (see doc/threads.txt) |
497
| conn_yields | 64u | Number of times any connection yielded to |
498
| | | another due to hitting the -R limit. |
499
| hash_power_level | 32u | Current size multiplier for hash table |
500
| hash_bytes | 64u | Bytes currently used by hash tables |
501
| hash_is_expanding | bool | Indicates if the hash table is being |
502
| | | grown to a new size |
503
| expired_unfetched | 64u | Items pulled from LRU that were never |
504
| | | touched by get/incr/append/etc before |
506
| evicted_unfetched | 64u | Items evicted from LRU that were never |
507
| | | touched by get/incr/append/etc. |
508
| slab_reassign_running | bool | If a slab page is being moved |
509
| slabs_moved | 64u | Total slab pages moved |
510
|-----------------------+---------+-------------------------------------------|
514
CAVEAT: This section describes statistics which are subject to change in the
517
The "stats" command with the argument of "settings" returns details of
518
the settings of the running memcached. This is primarily made up of
519
the results of processing commandline options.
521
Note that these are not guaranteed to return in any specific order and
522
this list may not be exhaustive. Otherwise, this returns like any
525
|-------------------+----------+----------------------------------------------|
526
| Name | Type | Meaning |
527
|-------------------+----------+----------------------------------------------|
528
| maxbytes | size_t | Maximum number of bytes allows in this cache |
529
| maxconns | 32 | Maximum number of clients allowed. |
530
| tcpport | 32 | TCP listen port. |
531
| udpport | 32 | UDP listen port. |
532
| inter | string | Listen interface. |
533
| verbosity | 32 | 0 = none, 1 = some, 2 = lots |
534
| oldest | 32u | Age of the oldest honored object. |
535
| evictions | on/off | When off, LRU evictions are disabled. |
536
| domain_socket | string | Path to the domain socket (if any). |
537
| umask | 32 (oct) | umask for the creation of the domain socket. |
538
| growth_factor | float | Chunk size growth factor. |
539
| chunk_size | 32 | Minimum space allocated for key+value+flags. |
540
| num_threads | 32 | Number of threads (including dispatch). |
541
| stat_key_prefix | char | Stats prefix separator character. |
542
| detail_enabled | bool | If yes, stats detail is enabled. |
543
| reqs_per_event | 32 | Max num IO ops processed within an event. |
544
| cas_enabled | bool | When no, CAS is not enabled for this server. |
545
| tcp_backlog | 32 | TCP listen backlog. |
546
| auth_enabled_sasl | yes/no | SASL auth requested and enabled. |
547
| item_size_max | size_t | maximum item size |
548
| maxconns_fast | bool | If fast disconnects are enabled |
549
| hashpower_init | 32 | Starting size multiplier for hash table |
550
| slab_reassign | bool | Whether slab page reassignment is allowed |
551
| slab_automove | bool | Whether slab page automover is enabled |
552
|-------------------+----------+----------------------------------------------|
557
CAVEAT: This section describes statistics which are subject to change in the
560
The "stats" command with the argument of "items" returns information about
561
item storage per slab class. The data is returned in the format:
563
STAT items:<slabclass>:<stat> <value>\r\n
565
The server terminates this list with the line
569
The slabclass aligns with class ids used by the "stats slabs" command. Where
570
"stats slabs" describes size and memory usage, "stats items" shows higher
573
The following item values are defined as of writing.
576
------------------------------
577
number Number of items presently stored in this class. Expired
578
items are not automatically excluded.
579
age Age of the oldest item in the LRU.
580
evicted Number of times an item had to be evicted from the LRU
582
evicted_nonzero Number of times an item which had an explicit expire
583
time set had to be evicted from the LRU before it
585
evicted_time Seconds since the last access for the most recent item
586
evicted from this class. Use this to judge how
587
recently active your evicted data is.
588
outofmemory Number of times the underlying slab class was unable to
589
store a new item. This means you are running with -M or
591
tailrepairs Number of times we self-healed a slab with a refcount
592
leak. If this counter is increasing a lot, please
593
report your situation to the developers.
594
reclaimed Number of times an entry was stored using memory from
596
expired_unfetched Number of expired items reclaimed from the LRU which
597
were never touched after being set.
598
evicted_unfetched Number of valid items evicted from the LRU which were
599
never touched after being set.
601
Note this will only display information about slabs which exist, so an empty
602
cache will return an empty set.
607
CAVEAT: This section describes statistics which are subject to change in the
610
The "stats" command with the argument of "sizes" returns information about the
611
general size and count of all items stored in the cache.
612
WARNING: This command WILL lock up your cache! It iterates over *every item*
613
and examines the size. While the operation is fast, if you have many items
614
you could prevent memcached from serving requests for several seconds.
616
The data is returned in the following format:
620
The server terminates this list with the line
624
'size' is an approximate size of the item, within 32 bytes.
625
'count' is the amount of items that exist within that 32-byte range.
627
This is essentially a display of all of your items if there was a slab class
628
for every 32 bytes. You can use this to determine if adjusting the slab growth
629
factor would save memory overhead. For example: generating more classes in the
630
lower range could allow items to fit more snugly into their slab classes, if
631
most of your items are less than 200 bytes in size.
636
CAVEAT: This section describes statistics which are subject to change in the
639
The "stats" command with the argument of "slabs" returns information about
640
each of the slabs created by memcached during runtime. This includes per-slab
641
information along with some totals. The data is returned in the format:
643
STAT <slabclass>:<stat> <value>\r\n
644
STAT <stat> <value>\r\n
646
The server terminates this list with the line
650
|-----------------+----------------------------------------------------------|
652
|-----------------+----------------------------------------------------------|
653
| chunk_size | The amount of space each chunk uses. One item will use |
654
| | one chunk of the appropriate size. |
655
| chunks_per_page | How many chunks exist within one page. A page by |
656
| | default is less than or equal to one megabyte in size. |
657
| | Slabs are allocated by page, then broken into chunks. |
658
| total_pages | Total number of pages allocated to the slab class. |
659
| total_chunks | Total number of chunks allocated to the slab class. |
660
| get_hits | Total number of get requests serviced by this class. |
661
| cmd_set | Total number of set requests storing data in this class. |
662
| delete_hits | Total number of successful deletes from this class. |
663
| incr_hits | Total number of incrs modifying this class. |
664
| decr_hits | Total number of decrs modifying this class. |
665
| cas_hits | Total number of CAS commands modifying this class. |
666
| cas_badval | Total number of CAS commands that failed to modify a |
667
| | value due to a bad CAS id. |
668
| touch_hits | Total number of touches serviced by this class. |
669
| used_chunks | How many chunks have been allocated to items. |
670
| free_chunks | Chunks not yet allocated to items, or freed via delete. |
671
| free_chunks_end | Number of free chunks at the end of the last allocated |
673
| mem_requested | Number of bytes requested to be stored in this slab[*]. |
674
| active_slabs | Total number of slab classes allocated. |
675
| total_malloced | Total amount of memory allocated to slab pages. |
676
|-----------------+----------------------------------------------------------|
678
* Items are stored in a slab that is the same size or larger than the
679
item. mem_requested shows the size of all items within a
680
slab. (total_chunks * chunk_size) - mem_requested shows memory
681
wasted in a slab class. If you see a lot of waste, consider tuning
687
"flush_all" is a command with an optional numeric argument. It always
688
succeeds, and the server sends "OK\r\n" in response (unless "noreply"
689
is given as the last parameter). Its effect is to invalidate all
690
existing items immediately (by default) or after the expiration
691
specified. After invalidation none of the items will be returned in
692
response to a retrieval command (unless it's stored again under the
693
same key *after* flush_all has invalidated the items). flush_all
694
doesn't actually free all the memory taken up by existing items; that
695
will happen gradually as new items are stored. The most precise
696
definition of what flush_all does is the following: it causes all
697
items whose update time is earlier than the time at which flush_all
698
was set to be executed to be ignored for retrieval purposes.
700
The intent of flush_all with a delay, was that in a setting where you
701
have a pool of memcached servers, and you need to flush all content,
702
you have the option of not resetting all memcached servers at the
703
same time (which could e.g. cause a spike in database load with all
704
clients suddenly needing to recreate content that would otherwise
705
have been found in the memcached daemon).
707
The delay option allows you to have them reset in e.g. 10 second
708
intervals (by passing 0 to the first, 10 to the second, 20 to the
712
"version" is a command with no arguments:
716
In response, the server sends
718
"VERSION <version>\r\n", where <version> is the version string for the
721
"verbosity" is a command with a numeric argument. It always succeeds,
722
and the server sends "OK\r\n" in response (unless "noreply" is given
723
as the last parameter). Its effect is to set the verbosity level of
726
"quit" is a command with no arguments:
730
Upon receiving this command, the server closes the
731
connection. However, the client may also simply close the connection
732
when it no longer needs it, without issuing this command.
738
For very large installations where the number of clients is high enough
739
that the number of TCP connections causes scaling difficulties, there is
740
also a UDP-based interface. The UDP interface does not provide guaranteed
741
delivery, so should only be used for operations that aren't required to
742
succeed; typically it is used for "get" requests where a missing or
743
incomplete response can simply be treated as a cache miss.
745
Each UDP datagram contains a simple frame header, followed by data in the
746
same format as the TCP protocol described above. In the current
747
implementation, requests must be contained in a single UDP datagram, but
748
responses may span several datagrams. (The only common requests that would
749
span multiple datagrams are huge multi-key "get" requests and "set"
750
requests, both of which are more suitable to TCP transport for reliability
753
The frame header is 8 bytes long, as follows (all values are 16-bit integers
754
in network byte order, high byte first):
758
4-5 Total number of datagrams in this message
759
6-7 Reserved for future use; must be 0
761
The request ID is supplied by the client. Typically it will be a
762
monotonically increasing value starting from a random seed, but the client
763
is free to use whatever request IDs it likes. The server's response will
764
contain the same ID as the incoming request. The client uses the request ID
765
to differentiate between responses to outstanding requests if there are
766
several pending from the same server; any datagrams with an unknown request
767
ID are probably delayed responses to an earlier request and should be
770
The sequence number ranges from 0 to n-1, where n is the total number of
771
datagrams in the message. The client should concatenate the payloads of the
772
datagrams for a given response in sequence number order; the resulting byte
773
stream will contain a complete response in the same format as the TCP
774
protocol (including terminating \r\n sequences).