Added new python test file, and made __echo respond with users JSVM

This commit is contained in:
Jonatan Pålsson 2011-02-01 01:40:21 +01:00
parent 2c083dd3dd
commit 30cebd1c0d
6 changed files with 64 additions and 14853 deletions

20
echo_test Executable file
View 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

File diff suppressed because one or more lines are too long

Binary file not shown.

22
python_client Executable file
View 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()

View file

@ -20,6 +20,9 @@ parse(Data) ->
{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};
Other ->

View file

@ -101,17 +101,20 @@ do_JSCall(Socket, Data, State) ->
Ret = js_runner:call(JSVM, "userCommand",
[list_to_binary(Command),
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
{hello} ->
Client = make_ref(),
Client = getRef(),
send(Socket, Client, "__ok_hello"),
{Client, JSVM};
{echo, RefID, _, MSG} ->
send(Socket, RefID, "Your VM is ", getJSVM(RefID, State)),
[];
% Set the new state to []
Other ->
io:format("Got '~p'", [Other]),
send(Socket, "__error"),
send(Socket, "RefID", "__error"),
[]
end,
% Return the new state
@ -119,9 +122,18 @@ do_JSCall(Socket, Data, State) ->
%%-----------------------------------------------------
%% Helpers
%%-----------------------------------------------------
getRef() ->
{A1,A2,A3} = now(),
random:seed(A1, A2, A3),
random:uniform(1000).
send(Socket, String) ->
gen_tcp:send(Socket, io_lib:fwrite("~p~n", [String])).
getJSVM(RefID, State) ->
VMs = State#state.client_vm_map,
{value, {_,VM}} = lists:keysearch(RefID, 1, VMs),
VM.
send(Socket, String1, String2) ->
gen_tcp:send(Socket, io_lib:fwrite("~p ~p~n", [String1, String2])).
send(Socket, RefID, String) ->
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])).