Sha256: d1cce1a7c50b471b32bae3383be567bd80c5f5dfb39eda33d7ad147d35c64b49

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

-module (client_server).
-include_lib("../include/defines.hrl").
-export([loop/1, connect_to_master/0]).
-export ([start/0]).

-define (RECONNECT_TIMEOUT, 10000).

start() -> 
	?TRACE("MASTER_LOCATION", [?MASTER_LOCATION]),
	connect_to_master(),
	global:sync(),
	pm_client:start(?MODULE, 7050, {?MODULE, loop}).
	
master_server() -> global:whereis_name(pm_master).

loop(Socket) ->
    case gen_tcp:recv(Socket, 0) of
        {ok, Data} ->
						?TRACE("received", [master_server(), erlang:binary_to_list(Data)]),
						% Args = [Item || K <- string:tokens(erlang:binary_to_list(Data), " "), Item <- erlang:list_to_atom(K)],
						[Meth|Args] = string:tokens(erlang:binary_to_list(Data), " "),
						?TRACE("received", [Meth, Args]),
						Output = gen_server:call(master_server(), {erlang:list_to_atom(Meth), Args}),
						?TRACE("received from gen_server", [Output]),
            gen_tcp:send(Socket, erlang:float_to_list(Output)),
						io:format("~p~n", [Output]),
						?TRACE("posted", [Output]),
            loop(Socket);
        {error, closed} ->
            ok
    end.

connect_to_master() ->
	case net_adm:ping(?MASTER_LOCATION) of
		pong ->
			ok;
		_ ->
			receive 
				stop -> void 
			after ?RECONNECT_TIMEOUT -> 
				connect_to_master()
			end
	end.

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
auser-poolparty-0.2.49 lib/erlang/messenger/src/client_server.erl
auser-poolparty-0.2.50 lib/erlang/messenger/src/client_server.erl
auser-poolparty-0.2.51 lib/erlang/messenger/src/client_server.erl
auser-poolparty-0.2.52 lib/erlang/messenger/src/client_server.erl
auser-poolparty-0.2.53 lib/erlang/messenger/src/client_server.erl