Added new python test file, and made __echo respond with users JSVM
This commit is contained in:
parent
2c083dd3dd
commit
30cebd1c0d
6 changed files with 64 additions and 14853 deletions
20
echo_test
Executable file
20
echo_test
Executable file
|
@ -0,0 +1,20 @@
|
||||||
|
#!/usr/bin/env ruby -wKU
|
||||||
|
|
||||||
|
require 'socket' # Sockets are in standard library
|
||||||
|
|
||||||
|
hostname = 'localhost'
|
||||||
|
port = 7000
|
||||||
|
|
||||||
|
print "Which port @ loclhost?"
|
||||||
|
port = gets
|
||||||
|
|
||||||
|
s = TCPSocket.open(hostname, port.chop)
|
||||||
|
|
||||||
|
s.print("__hello")
|
||||||
|
|
||||||
|
while true
|
||||||
|
line = s.gets # Read lines from the socket
|
||||||
|
puts ">> " + line.chop # And print with platform line terminator
|
||||||
|
s.print(gets.chop)
|
||||||
|
end
|
||||||
|
s.close # Close the socket when done
|
14846
erl_crash.dump
14846
erl_crash.dump
File diff suppressed because one or more lines are too long
Binary file not shown.
22
python_client
Executable file
22
python_client
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import socket
|
||||||
|
|
||||||
|
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')
|
||||||
|
fs = s.makefile()
|
||||||
|
data = fs.readline()
|
||||||
|
token = data.split(" ")[0]
|
||||||
|
print "Token:", token
|
||||||
|
|
||||||
|
s.send(token+" __echo 0 msg")
|
||||||
|
data = s.recv(1024)
|
||||||
|
print data
|
||||||
|
|
||||||
|
s.close()
|
||||||
|
|
|
@ -20,6 +20,9 @@ parse(Data) ->
|
||||||
{hello};
|
{hello};
|
||||||
[RefID, "__define",_, JavaScript ] ->
|
[RefID, "__define",_, JavaScript ] ->
|
||||||
{ok, you_said_define};
|
{ok, you_said_define};
|
||||||
|
[RefID, "__echo", Length, Msg ] ->
|
||||||
|
{Ref, _} = string:to_integer(RefID),
|
||||||
|
{echo, Ref, Length, Msg};
|
||||||
[RefID, Command, _, Parameter ] ->
|
[RefID, Command, _, Parameter ] ->
|
||||||
{cmd, Command, Parameter};
|
{cmd, Command, Parameter};
|
||||||
Other ->
|
Other ->
|
||||||
|
|
|
@ -101,17 +101,20 @@ do_JSCall(Socket, Data, State) ->
|
||||||
Ret = js_runner:call(JSVM, "userCommand",
|
Ret = js_runner:call(JSVM, "userCommand",
|
||||||
[list_to_binary(Command),
|
[list_to_binary(Command),
|
||||||
list_to_binary(Parameter)]),
|
list_to_binary(Parameter)]),
|
||||||
send(Socket, "JS says: ", Ret),
|
send(Socket, "RefID", "JS says: ", Ret),
|
||||||
[];
|
[];
|
||||||
% Set the new state to the reference generated, and JSVM associated
|
% Set the new state to the reference generated, and JSVM associated
|
||||||
{hello} ->
|
{hello} ->
|
||||||
Client = make_ref(),
|
Client = getRef(),
|
||||||
send(Socket, Client, "__ok_hello"),
|
send(Socket, Client, "__ok_hello"),
|
||||||
{Client, JSVM};
|
{Client, JSVM};
|
||||||
|
{echo, RefID, _, MSG} ->
|
||||||
|
send(Socket, RefID, "Your VM is ", getJSVM(RefID, State)),
|
||||||
|
[];
|
||||||
% Set the new state to []
|
% Set the new state to []
|
||||||
Other ->
|
Other ->
|
||||||
io:format("Got '~p'", [Other]),
|
io:format("Got '~p'", [Other]),
|
||||||
send(Socket, "__error"),
|
send(Socket, "RefID", "__error"),
|
||||||
[]
|
[]
|
||||||
end,
|
end,
|
||||||
% Return the new state
|
% Return the new state
|
||||||
|
@ -119,9 +122,18 @@ do_JSCall(Socket, Data, State) ->
|
||||||
%%-----------------------------------------------------
|
%%-----------------------------------------------------
|
||||||
%% Helpers
|
%% Helpers
|
||||||
%%-----------------------------------------------------
|
%%-----------------------------------------------------
|
||||||
|
getRef() ->
|
||||||
|
{A1,A2,A3} = now(),
|
||||||
|
random:seed(A1, A2, A3),
|
||||||
|
random:uniform(1000).
|
||||||
|
|
||||||
send(Socket, String) ->
|
getJSVM(RefID, State) ->
|
||||||
gen_tcp:send(Socket, io_lib:fwrite("~p~n", [String])).
|
VMs = State#state.client_vm_map,
|
||||||
|
{value, {_,VM}} = lists:keysearch(RefID, 1, VMs),
|
||||||
|
VM.
|
||||||
|
|
||||||
send(Socket, String1, String2) ->
|
send(Socket, RefID, String) ->
|
||||||
gen_tcp:send(Socket, io_lib:fwrite("~p ~p~n", [String1, String2])).
|
gen_tcp:send(Socket, io_lib:fwrite("~p ~p~n", [RefID,String])).
|
||||||
|
|
||||||
|
send(Socket, RefID, String1, String2) ->
|
||||||
|
gen_tcp:send(Socket, io_lib:fwrite("~p ~p ~p~n", [RefID, String1, String2])).
|
||||||
|
|
Reference in a new issue