[erlang-questions] Writing platform independent Socket based binary parsing code

Arun Muralidharan arun11299@REDACTED
Sat May 12 09:34:40 CEST 2012

Hi Folks,

I have an erlang application which includes parsing of binary data from
socket (both TCP and UDP). The binary data is as per some specific
protocol, so my options for TCP and UDP sock is as per below:

TCP sock :
Opts = [binary, {packet, 0}, {reuseaddr, true},
            {keepalive, true}, {backlog, 30}, {active, false}],

UDP sock :

Now, when i parse the data I get from socket, I do like this (On UNIX):

    << Version:4/big-unsigned-integer-unit:8,
       _Rest/binary >> = Bin_event_From_Socket.

Now, this would give me a problem when run on LINUX as LINUX is little
endian based. So, the option here for me is to convert 'big' to 'little' in
the above code.

But, Erlang being a VM based language, I must be having some facility to
write platform independent code. I searched the NEt but couldnt find much
on it.
So, the question here is how can i write a platform independent sockaet
data parsing code ?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120512/c1cf7b7c/attachment.htm>

More information about the erlang-questions mailing list