0

I have a cowboy ws handler with binary pattern matching as follows:

websocket_handle({text, <<"Reg: ",Message/binary>>}, Req, State)

I need to call this handler with js code, so I use Bert.js to encode js string variable to binary erlang term as follows:

 websocket.send(Bert.encode(Bert.binary("<<\"Reg: \" , \""+input2 + "\">>")));

But I couldn't invoke my handler with this encoded argument !!

Is my encoded argument wrong ? or is there another method to make an erlang binary term with js ?

H. SLF
  • 61
  • 8

2 Answers2

0

I didn't use Bert, but it seems that Bert.encode take as argument the string that must be converted to binary.

The Erlang notation uses <<...>> to identify the term as a binary, and the inner "..." to say to the compiler or the user that the elements of the binary are ascii characters. They are not part of the binary itself and should not be passed to the Bert.binary function.

I think that Bert.binary("Reg: " + input2) is correct.

Pascal
  • 13,977
  • 2
  • 24
  • 32
0

I used a brut js string and it's work now.

websocket.send("Reg: " +input2 );
H. SLF
  • 61
  • 8