-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcliente.erl
executable file
·37 lines (32 loc) · 1.22 KB
/
cliente.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-module(cliente).
-export([pedir_taxi/2, pide_taxi/2]).
-import('matriz', [genera_nodo/1]).
% La funcion genera_nodo genera la matriz a donde se conectara, con todo y su hostname
% En este caso, se genera servidor_taxi@HOSTNAME
nodo_servidor() -> genera_nodo("servidor_taxi").
% nodo_taxi() -> genera_nodo("taxi").
pedir_taxi(Quien, {X, Y}) ->
spawn(cliente, pide_taxi, [Quien, {X, Y}]).
% cliente
pide_taxi(Quien, {X, Y}) ->
Matriz = nodo_servidor(),
monitor_node(Matriz, true),
{servidor_taxi, Matriz} ! {pedir_cliente, Quien, {X, Y}, self()},
receive
{NumServicio, T_PID, Tipo, Placas} ->
io:format("~ts Se le asigno un auto tipo ~p con placas ~p. ~n", ["🚕",Tipo, Placas]),
io:format("~ts Su numero de servicio es: ~p | El T_PID de su taxi es: ~p. ~n", ["✔",NumServicio, T_PID]),
monitor_node(Matriz, false),
receive
{taxi, llega} ->
ok
after wait() ->
cancelar(T_PID)
end;
no_taxis_disponibles ->
noTaxi;
{nodedown, Matriz} ->
noServer
end.
cancelar(T_PID) -> T_PID ! {self(), cancelar}.
wait() -> rand:uniform(10000).