diff --git a/python_client b/python_client index 77574e6..4205c8c 100755 --- a/python_client +++ b/python_client @@ -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] diff --git a/src/ggs_protocol.erl b/src/ggs_protocol.erl index c470beb..48144c2 100644 --- a/src/ggs_protocol.erl +++ b/src/ggs_protocol.erl @@ -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. diff --git a/src/ggs_server.erl b/src/ggs_server.erl index 566d354..6c76a9d 100644 --- a/src/ggs_server.erl +++ b/src/ggs_server.erl @@ -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",