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

John Koenig koenigjm@REDACTED
Sun Jan 2 21:05:42 CET 2011


Code is attached.  

What you have said so far has brought me close of identifying the problem.  Up until now I have assumed that ei_decode_tuple_header would scan me ahead to the proper location, but I starting to think I was wrong to do so.  Especially after looking at the received data more closely in gdb.

How does one know the proper offset from which to start decoding the actual message?

John

-------------- next part --------------



On Jan 2, 2011, at 1:48 PM, Steve Vinoski wrote:

> On Sun, Jan 2, 2011 at 2:29 PM, John Koenig <koenigjm@REDACTED> wrote:
>> I am currently porting a server process (written in C) to ei, which used to interact with an
>> erlang process via the older erl_interface.  I am able to get the the two sides talking over a
>> localhost TCP socket, but I am having trouble decoding the tuples sent to the C based server.
>> 
>> Tuples are being sent from an interactive erlang session as follows:
>> 
>> {any, mynode@REDACTED} ! {tuple1, typle2, []}
>> 
>> When the message is received in the C based server via ei_receive,  however,
>> ei_decode_tuple_header returns non-zero and I am unable to proceed further.  Calling
>> ei_get_type on the buffer results in 'p' which, according to ei.h, corresponds to
>> ERL_NEW_FUN_EXT.  Why is this failing and why is this tuple being reported as an
>> ERL_NEW_FUN_EXT?
>> 
>> The only example I have seen thus far
>> (http://www.trapexit.org/How_to_use_ei_to_marshal_binary_terms_in_port_programs) uses ei
>> stdin/stdout, can ei be used over a TCP socket at all?
> 
> Ei most definitely works over TCP. Can you post more of your decoding
> code? Hard to tell what's going on from what you've told us so far,
> but p is value 112 and there are a couple instances of that value in
> the encoded form of your tuple above, so you're likely just decoding
> at the wrong offset.
> 
> --steve



More information about the erlang-questions mailing list