[erlang-questions] Decoding Erlang Messages Sent Over TCP With EI

Steve Vinoski <>
Mon Jan 3 01:27:04 CET 2011

On Sun, Jan 2, 2011 at 4:04 PM, John Koenig <> wrote:
> I have just retried calling ei_decode_version before decode_tuple_header, and it returns -1.
> Below is the output from gdb when I display the contents of the message buffer:
> (gdb) p/x *
> $3 = {0x70, 0x83, 0x68, 0x4, 0x61, 0x6, 0x67, 0x64, 0x0, 0xb, 0x65, 0x72, 0x6c, 0x79, 0x40,
> 0x73, 0x68, 0x61, 0x64, 0x6f, 0x77, 0x0, 0x0, 0x0, 0x25, 0x0, 0x0, 0x0, 0x0, 0x3, 0x64, 0x0,
> 0x0, 0x64, 0x0, 0x3, 0x61, 0x6e, 0x79, 0x83, 0x68, 0x3, 0x64, 0x0, 0x6, 0x74, 0x75, 0x70,
> 0x6c, 0x65, 0x30, 0x64, 0x0, 0x6, 0x74, 0x75, 0x70, 0x6c, 0x65, 0x31, 0x6a}

I believe the 'p' (value 0x70) you see here is the ERL_PASS_THROUGH
indicator, which I think indicates that the message contains both
addressing information metadata for the recipient along with the
message being sent to that recipient. This is what we see in your data

0x83: ERL_VERSION_MAGIC (version number)
tuple header showing a 4-tuple
the value 6, indicating an ERL_REG_SEND message
the pid of the sender
an atom for the cookie (empty here)
the atom 'any'
0x83 ERL_VERSION_MAGIC (version number)
tuple header showing a 3-tuple
the atom 'tuple0'
the atom 'tuple1'
0x6A: the nil indicator (for the empty list)

Instead of having to decode all this yourself, just use ei_receive_msg
or ei_xreceive_msg to retrieve your messages, as these functions will
first decode the addressing info and use it to populate an erlang_msg
struct, and then you can use your existing code to decode the message
itself. The ei_x_buff struct you pass to these functions contains a
pointer to the encoded buffer and an index member that the functions
will fill in to tell you where to start decoding.


More information about the erlang-questions mailing list