sending data between erlang and c++ -
i using tcp connection send data c++ server. have read ei library when given binary has bunch of functions decoded value out of binary. egs, ei_decode_string, ei_decode_long , others.
i trying these simple things:
1. create socket , connect it.
{ok, socket} = gen_tcp:connect({127,0,0,1}, 8986, []).
2. use gen_tcp:send/2 send data.
gen_tcp:send(socket, term_to_binary("stackoverflow")).
therefore, sending binary format of string server.
my server, c++ code, gets data , trying whatever client sends me on socket using ei_decode_string like:
ideally, when decoded should string, "stackoverflow" since told decode_as_string binary. made sure had enough space in resulting buffer.
char *p = (char*)malloc(sizeof(char) * 100); int index = 0; int decoded = ei_decode_string(buff, &index, p); cout<<"the decoded value "<<p<<endl;
i not able decode string sent.! missing something? how can send data , decode on server side, if not right approach.
thank help!
1> term_to_binary("stackoverflow"). <<131,107,0,13,83,116,97,99,107,111,118,101,114,102,108, 111,119>>
here first item in binary not string small integers, version number (131) described in external term format. after comes terms each prefixed tag , corresponding data. in case tag 107 string_ext
, 2 bytes length (13) , 13 8bit integers, first 1 83 corresponds letter 's' (83 in ascii).
to handle binary correctly correctly, call ei_decode_version
has before ei_decode_string
int ei_decode_version(const char *buf, int *index, int *version)
this function decodes version magic number erlang binary term format. must first token in binary term.
Comments
Post a Comment