From e2d79c5681187aee43aa422e9f621329dbb71c9b Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 28 Oct 2015 19:20:31 +0100 Subject: Use messages --- tda.erl | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) (limited to 'tda.erl') diff --git a/tda.erl b/tda.erl index 48eb9e0..e8d863f 100644 --- a/tda.erl +++ b/tda.erl @@ -10,9 +10,14 @@ start() -> register(tdaPid, spawn(?MODULE, client, [{dial, ?HOST, ?PORT}])). -stop() -> tdaPid ! logout. -ext() -> tdaPid ! ext. -co() -> tdaPid ! co. +stop() -> + tdaPid ! acse:release(). + +ext() -> + tdaPid ! rose:invoke({present, 2}, {local, 51}, csta:ext_lines()). + +co() -> + tdaPid ! rose:invoke({present, 2}, {local, 51}, csta:co_lines()). client({dial, Host, Port}) -> io:format("Dial ~p:~p~n", [Host, Port]), @@ -20,10 +25,12 @@ client({dial, Host, Port}) -> [binary, {active, once}, {packet, 2}], ?CONNECT_TIMEOUT), client(Conn); + client({ok, Sock}) -> io:format("Connected~n", []), - tdaPid ! login, + tdaPid ! acse:associate(), loop(Sock); + client({error, Reason}) -> io:format("Error: ~p~n", [Reason]), {error, Reason}. @@ -32,34 +39,16 @@ loop(Sock) -> inet:setopts(Sock, [{active, once}]), io:format("Loop~n", []), receive - login -> - io:format("Login~n", []), - {ok, Hello} = acse:associate(), - gen_tcp:send(Sock, Hello); - logout -> - io:format("Logout~n", []), - {ok, Bye} = acse:release(), - gen_tcp:send(Sock, Bye); - ext -> - io:format("Request Ext lines~n", []), - {ok, Rq} = rose:invoke({present, 2}, - {local, 51}, csta:ext_lines()), - io:format("Send: ~p~n", [Rq]), - gen_tcp:send(Sock, Rq); - co -> - io:format("Request CO lines~n", []), - {ok, Rq} = rose:invoke({present, 2}, - {local, 51}, csta:co_lines()), - io:format("Send: ~p~n", [Rq]), - gen_tcp:send(Sock, Rq); + {ok, Reply} -> + io:format("Send ~p~n", [Reply]), + gen_tcp:send(Sock, Reply); {tcp, Sock, Data} -> io:format("Got ~p~n", [Data]), case decode(Data) of ok -> ok; {ok, Reply} -> - io:format("Reply ~p~n", [Reply]), - gen_tcp:send(Sock, Reply); + tdaPid ! {ok, Reply}; error -> exit(error) end; -- cgit v1.2.3