Started working on the new protocol

This commit is contained in:
Jonatan Pålsson 2011-02-02 21:19:33 +01:00
parent ae9034934e
commit f5fac06849
3 changed files with 58 additions and 30 deletions

View file

@ -8,7 +8,13 @@ HOST = 'localhost' # The remote host
PORT = int(sys.argv[1]) # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('__hello 0')
s.send(
'Token: 1001\n\
Command: define\n\
Content-Type: text\n\
Content-Length: 40\n\
\n\
function helloWorld(x) {return x + 2 ;}')
fs = s.makefile()
data = fs.readline()
token = data.split(" ")[0]

View file

@ -5,32 +5,51 @@
-export([parse/1]).
parse(Data) ->
Message = string:tokens(Data, " "),
io:format(Message),
case Message of
["__get_vms"] ->
{vms};
[RefID, "__error", Size, Message ] ->
{ok, you_said_error};
[_, "__boot", _ ] ->
{ok, you_said_boot};
[RefID, "__stop", _] ->
{ok, you_said_stop};
[RefID, "__start", _] ->
{ok, you_said_start};
["__hello", _] ->
{hello};
[RefID, "__define",_, JavaScript ] ->
{ok, you_said_define};
[RefID, "__echo", Length, Msg ] ->
{Ref, _} = string:to_integer(RefID),
{echo, Ref, Length, Msg};
[RefID, Command, _, Parameter ] ->
{cmd, Command, Parameter};
%% Debugging tools, not for production use
["__crash"] ->
{crash, 0};
%% End debugging tools
Other ->
{out_of_bounds, Other}
end.
Message =string:tokens(Data, "\n"),
% Turn "A: B" pairs into "{A, B}" tuples, for searching.
MsgKV = lists:map((fun(Str) ->
list_to_tuple(string:tokens(Str, ": ")) end
), Message),
% Hacky way to build a tuple, filter out not_found later on
Processed = {
case lists:keysearch("Token", 1, MsgKV) of
{value,{_, Value}} ->
Value;
false ->
not_found
end,
case lists:keysearch("Command", 1, MsgKV) of
{value,{_, "define"}} ->
define;
false ->
not_found
end
},
Processed.
% case Message of
% ["__get_vms"] ->
% {vms};
% [RefID, "__error", Size, Message ] ->
% {ok, you_said_error};
% [_, "__boot", _ ] ->
% {ok, you_said_boot};
% [RefID, "__stop", _] ->
% {ok, you_said_stop};
% [RefID, "__start", _] ->
% {ok, you_said_start};
% ["__hello", _] ->
% {hello};
% [RefID, "__define",_, JavaScript ] ->
% {ok, you_said_define};
% [RefID, "__echo", Length, Msg ] ->
% {Ref, _} = string:to_integer(RefID),
% {echo, Ref, Length, Msg};
% [RefID, Command, _, Parameter ] ->
% {cmd, Command, Parameter};
% %% Debugging tools, not for production use
% ["__crash"] ->
% {crash, 0};
% %% End debugging tools
% Other ->
% {out_of_bounds, Other}
% end.

View file

@ -98,6 +98,9 @@ do_JSCall(Socket, Data, State) ->
js_runner:define(JSVM, "function userCommand(cmd, par) {return cmd+' '+ par}"),
Parsed = ggs_protocol:parse(Data),
NewState = case Parsed of
{Token, define} ->
io:format("Got define!!\n"),
[];
{cmd, Command, Parameter} ->
% Set the new state to []
Ret = js_runner:call(JSVM, "userCommand",