1

I have an erlang client which is sending me data using gen_tcp:send/2

Specifically, it is sending me like this,

   gen_tcp:send(Socket, <<A:16, B:16, Message/binary>>)

I have a c++ based, tcp server, that receives the message. If the client could have sent me using term_to_binary/1 I could have used ei_decode_X and decoded. Not sure How to receive this specific message and able to parse it. i.e, I should know the Message, values of A, B.

I receive this data using

   recv(sock , client_message , 2000 , 0)

I can see that there is not data being received at all when I send like that. However, if I send it after term_to_binary/1 conversion, I am able to receive data.

Is it a proper way of sending data ?

Thanks

listen
  • 217
  • 2
  • 7
  • What are `A` `B` and `Message` bound to? – Nathaniel Waisbrot Apr 26 '16 at 01:22
  • For eg, A can be 1, B can be 0 and Message can be anything – listen Apr 26 '16 at 01:35
  • Erlang `send` function accepts `iodata`, which means it accepts lists or binaries. So it's a correct way of sending data. The data will be send verbatim, e.g. if `A` is `1` and `B`is `0` in `recv` you will get bytes `1000`. Similarly for the Message. When you say that no data is received, what `recv` returns? It should have returned the amount of bytes received. You can try to use the `MSG_WAITALL` flag. BTW term to binary also returns a binary, it just contains additional metadata bytes to describe the size and type of the data contained in it. Try to execute it in Erlang shell. – Greg Apr 26 '16 at 09:17

0 Answers0