Skip to content

Commit

Permalink
Support for arbitrary Eclients
Browse files Browse the repository at this point in the history
  • Loading branch information
sigstop committed May 17, 2013
1 parent 364024f commit 8d5e931
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/econnect.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,23 @@ stop(_Servername,IPAddress,Port,Docroot) ->
handle_message({text, <<"ES_ONLINE">>}) ->
Pid = self(),
register(eserver,self()),
error_logger:info_msg("EServer Registered as {eserver,~p}~n",[Pid]);
error_logger:info_msg("EServer Registered as {eserver,~p}~n",[Pid]),
noreply;
handle_message({close,_Num,_Bin}) ->
unregister(eserver),
error_logger:info_msg("EServer Disconnected and Unregistered~n");
error_logger:info_msg("EServer Disconnected and Unregistered~n"),
noreply;

handle_message({text,B})->
<<_H,T/binary>> = B,
Term = binary_to_term(T),
error_logger:info_msg("Binary Received:~n~p~n",[B]),
error_logger:info_msg("Term Received:~n~p~n",[Term]),
error_logger:info_msg("My Pid = ~p~n",[self()]),
spawn(eclient_stub,handle_message,[Term]);
spawn(eclient_stub,handle_message,[Term]),
noreply;


handle_message(A)->
error_logger:info_msg("Received:~n~p~n",[A]),
error_logger:info_msg("My Pid = ~p~n",[self()]),
Expand Down
2 changes: 1 addition & 1 deletion www/eport.yaws
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<erl>
out(A) ->
CallbackMod = econnect,
Opts = [{origin, "http://" ++ (A#arg.headers)#headers.host}],
Opts = [{origin, any}],
{websocket, CallbackMod, Opts}.
</erl>
</html>
7 changes: 6 additions & 1 deletion www/js/e.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function createUUID() {
// connection.send('CONNECT'); // Send the message 'Ping' to the server
connection.onopen = function () {
var Value = 1;
connection.send(Bert.encode(Bert.tuple(Bert.atom("hello"),Value))); // Notification that th EServer is online
connection.send('ES_ONLINE');
connection.send(Bert.encode(Bert.tuple(Bert.atom("hello"),Value))); // Notification that th EServer is online
};

var ProcCode;
Expand Down Expand Up @@ -60,6 +60,9 @@ var emsg_handle = function(tuple) {
case 'erl_form_result':
deliverResult(tuple);
break;
case 'flow_table_data':
deliverFlowTable(tuple);
break;
default:
alert("The EClient sent unknown command: " + command)
}
Expand Down Expand Up @@ -297,9 +300,11 @@ connection.onmessage = function(msg) {
var reader = new FileReader();
reader.onloadend = function() {
var string = reader.result;
console.log(string);
Message = Bert.decode(string);
console.log(Message.toString());
var tuple = Message.value;
console.log(tuple[2].toString());
emsg_handle(tuple);
};
reader.readAsBinaryString(blob );
Expand Down

0 comments on commit 8d5e931

Please sign in to comment.