[erlang-questions] One more question?

Michael erlangy@REDACTED
Fri Feb 12 21:38:21 CET 2010


On Fri, Feb 12, 2010 at 12:32:06PM -0800, Michael wrote:
> On Fri, Feb 12, 2010 at 03:03:02PM -0500, Ish Rattan wrote:
> >
> > Erlang server gets message from non-Erlang client as:
> > <<0,0,0,10,72,101,108,108,111,46,46>>
> > (numeric 10 in 4-bytes followed by "hello..")
> >
> > how to extract the pieces?
> >
> > -ishwar
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
>  Also see Programming Examples in docs.
> 
>  This should work if you can be assured that the first 4 bytes
>  are always before the message.
> 
> 1> <<Bytes:4/binary, Msg/binary>> = <<0,0,0,10,72,101,108,108,111,46,46>>.
> 2> Msg.
> <<"Hello..">>
> 3>
> 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  or, another way to "slice the baloney" ...


3> [_,_,_,_ | Rest] = binary_to_list( <<0,0,0,10,72,101,108,108,111,46,46>> ).
[0,0,0,10,72,101,108,108,111,46,46]
4> Rest.
"Hello.."
5>


~Michael


More information about the erlang-questions mailing list