Started working on the new protocol
This commit is contained in:
parent
ae9034934e
commit
f5fac06849
3 changed files with 58 additions and 30 deletions
|
@ -8,7 +8,13 @@ HOST = 'localhost' # The remote host
|
||||||
PORT = int(sys.argv[1]) # The same port as used by the server
|
PORT = int(sys.argv[1]) # The same port as used by the server
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
s.connect((HOST, PORT))
|
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()
|
fs = s.makefile()
|
||||||
data = fs.readline()
|
data = fs.readline()
|
||||||
token = data.split(" ")[0]
|
token = data.split(" ")[0]
|
||||||
|
|
|
@ -5,32 +5,51 @@
|
||||||
-export([parse/1]).
|
-export([parse/1]).
|
||||||
|
|
||||||
parse(Data) ->
|
parse(Data) ->
|
||||||
Message = string:tokens(Data, " "),
|
Message =string:tokens(Data, "\n"),
|
||||||
io:format(Message),
|
% Turn "A: B" pairs into "{A, B}" tuples, for searching.
|
||||||
case Message of
|
MsgKV = lists:map((fun(Str) ->
|
||||||
["__get_vms"] ->
|
list_to_tuple(string:tokens(Str, ": ")) end
|
||||||
{vms};
|
), Message),
|
||||||
[RefID, "__error", Size, Message ] ->
|
% Hacky way to build a tuple, filter out not_found later on
|
||||||
{ok, you_said_error};
|
Processed = {
|
||||||
[_, "__boot", _ ] ->
|
case lists:keysearch("Token", 1, MsgKV) of
|
||||||
{ok, you_said_boot};
|
{value,{_, Value}} ->
|
||||||
[RefID, "__stop", _] ->
|
Value;
|
||||||
{ok, you_said_stop};
|
false ->
|
||||||
[RefID, "__start", _] ->
|
not_found
|
||||||
{ok, you_said_start};
|
end,
|
||||||
["__hello", _] ->
|
case lists:keysearch("Command", 1, MsgKV) of
|
||||||
{hello};
|
{value,{_, "define"}} ->
|
||||||
[RefID, "__define",_, JavaScript ] ->
|
define;
|
||||||
{ok, you_said_define};
|
false ->
|
||||||
[RefID, "__echo", Length, Msg ] ->
|
not_found
|
||||||
{Ref, _} = string:to_integer(RefID),
|
end
|
||||||
{echo, Ref, Length, Msg};
|
},
|
||||||
[RefID, Command, _, Parameter ] ->
|
Processed.
|
||||||
{cmd, Command, Parameter};
|
% case Message of
|
||||||
%% Debugging tools, not for production use
|
% ["__get_vms"] ->
|
||||||
["__crash"] ->
|
% {vms};
|
||||||
{crash, 0};
|
% [RefID, "__error", Size, Message ] ->
|
||||||
%% End debugging tools
|
% {ok, you_said_error};
|
||||||
Other ->
|
% [_, "__boot", _ ] ->
|
||||||
{out_of_bounds, Other}
|
% {ok, you_said_boot};
|
||||||
end.
|
% [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.
|
||||||
|
|
|
@ -98,6 +98,9 @@ do_JSCall(Socket, Data, State) ->
|
||||||
js_runner:define(JSVM, "function userCommand(cmd, par) {return cmd+' '+ par}"),
|
js_runner:define(JSVM, "function userCommand(cmd, par) {return cmd+' '+ par}"),
|
||||||
Parsed = ggs_protocol:parse(Data),
|
Parsed = ggs_protocol:parse(Data),
|
||||||
NewState = case Parsed of
|
NewState = case Parsed of
|
||||||
|
{Token, define} ->
|
||||||
|
io:format("Got define!!\n"),
|
||||||
|
[];
|
||||||
{cmd, Command, Parameter} ->
|
{cmd, Command, Parameter} ->
|
||||||
% Set the new state to []
|
% Set the new state to []
|
||||||
Ret = js_runner:call(JSVM, "userCommand",
|
Ret = js_runner:call(JSVM, "userCommand",
|
||||||
|
|
Reference in a new issue