Added more protocol

This commit is contained in:
Jonatan Pålsson 2011-01-31 17:04:13 +01:00
parent 34b4c1d072
commit 43a51430bc
5 changed files with 3802 additions and 4406 deletions

View file

@ -10,10 +10,11 @@ port = gets
s = TCPSocket.open(hostname, port.chop)
s.print(" __boot")
s.print("__hello")
while true
line = s.gets # Read lines from the socket
puts "Got Echo: " + line.chop # And print with platform line terminator
puts ">> " + line.chop # And print with platform line terminator
s.print(gets.chop)
end
s.close # Close the socket when done

File diff suppressed because it is too large Load diff

View file

@ -6,20 +6,21 @@
parse(Data) ->
Message = string:tokens(Data, " "),
io:format(Message),
case Message of
[RefID, "__error", Message ] ->
[RefID, "__error", Size, Message ] ->
{ok, you_said_error};
[_, "__boot" ] ->
[_, "__boot", _ ] ->
{ok, you_said_boot};
[RefID, "__stop"] ->
[RefID, "__stop", _] ->
{ok, you_said_stop};
[RefID, "__start"] ->
[RefID, "__start", _] ->
{ok, you_said_start};
[_, "__hello" , _ ] ->
{ok, you_said_hello};
[RefID, "__define", JavaScript ] ->
["__hello", _] ->
{hello};
[RefID, "__define",_, JavaScript ] ->
{ok, you_said_define};
[RefID, Command, Parameter ] ->
[RefID, Command, _, Parameter ] ->
{cmd, Command, Parameter};
Other ->
{out_of_bounds, Other}

View file

@ -73,9 +73,7 @@ handle_cast(stop, State) ->
handle_info({tcp, Socket, RawData}, State) ->
do_JSDefine(Socket, RawData),
%Parsed = ggs_protocol:parse(RawData),
RequestCount = State#state.request_count,
%gen_tcp:send(Socket, io_lib:fwrite("~p~n", [Parsed])),
{noreply, State#state{request_count = RequestCount + 1}};
handle_info(timeout, #state{lsock = LSock} = State) ->
@ -101,10 +99,20 @@ do_JSDefine(Socket, Data) ->
Ret = js_runner:call(JSVM, "userCommand",
[list_to_binary(Command),
list_to_binary(Parameter)]),
gen_tcp:send(Socket, io_lib:fwrite("JS says: ~p~n", [Ret]));
send(Socket, "JS says: ", Ret);
{hello} ->
io:format("Got hello!"),
send(Socket, make_ref(), "__ok_hello");
Other ->
ok
io:format("Got '~p'", [Other]),
send(Socket, "__error")
end.
do_JSCall(Socket, Function, Parameters) ->
ok.
ok.
send(Socket, String) ->
gen_tcp:send(Socket, io_lib:fwrite("~p~n", [String])).
send(Socket, String1, String2) ->
gen_tcp:send(Socket, io_lib:fwrite("~p ~p~n", [String1, String2])).

View file

@ -1,14 +0,0 @@
-module(v8test).
-export([run/0]).
-include_lib("erlv8/include/erlv8.hrl").
run() ->
application:start(erlv8),
{ok, VM} = erlv8_vm:start(),
Global = erlv8_vm:global(VM),
Global:set_value("callback", erlv8_object:new([{"exec", fun (#erlv8_fun_invocation{}, []) -> myCallback() end}])),
erlv8_vm:run(VM,"callback.exec();").
myCallback() ->
io:format("Hello from myCallback!~n", []),
ok.