I created an N2o protocol that routes messages over different family of application, (before that I used a cowboy websocket handler to do this job)
So for example I have this code in my protocol to send a message to a registered process
> info({text,<<"REG:",Msg/binary>> }, Req, State) ->
> {[{_,Family}]}=jiffy:decode(Msg), Test = gproc:reg({p, l, Family},
> 1), {reply, <<"process registered successfully">>, Req, State};
info({text,<<"TRANSMIT:",Msg/binary>> }=M, Req, State) ->
{[{_,Type},{_,Action},{_,From},{_,To},{_,Message}]}=jiffy:decode(Msg),
gproc:send({p, l, To}, {self(),<<"Hi I am a good message!">>}),
{reply, <<"message transmitted successfully">>, Req, State};
In my HTML client , firstly I register under the protocol with
var msg = {family: "JS"}; websocket.send("REG:"+JSON.stringify(msg) );
And I verified that my html process was well registered
Then , From My same HTML client, I called the transmit protocol method like:
msg = {Type: "TRANSMIT:", Action: "Chat", From: "JS", To: "JS", Message:"Hello I am Js"}; websocket.send("TRANSMIT: "+JSON.stringify(msg) );
Basically in this stage I should receive a message contain "Hello I am Js" in my HTML client, but Always I received an empty data string like:
MessageEvent {isTrusted: true, data: "", origin: "ws://192.168.1.20:8000", lastEventId: "", source: null…}
INFO:
I well received the reply message as follows:
when registering process:
MessageEvent {isTrusted: true, data: "process registered successfully", origin: "ws://192.168.1.20:8000", lastEventId: "", source: null…}
when submitting message:
MessageEvent {isTrusted: true, data: "message transmitted successfully", origin: "ws://192.168.1.20:8000", lastEventId: "", source: null…}
Also When I used my cowboy ws handler I didn't experience such issue.