I am trying to make a master process here which willspawn the 5 processes and then these process will make a call to the people in the list. The text file is as follows :
{john, [jill,joe,bob]}. {jill, [bob,joe,bob]}. {sue, [jill,jill,jill,bob,jill]}. {bob, [john]}. {joe, [sue]}.
Blockquote
in it john is a process and will send a message to Jill, joe and bob. Same with the other processes. So far I was able to spawn the process and get the elements from the sublist but I donot know how to send the messages from processes to the sublists .I am a beginner in erlang and I am facing too much problem in it I have read a lot about the processes and concurrency and from many resources but this is way too much for me .the required output looks like this :
bob received intro message from jill [738000] joe received intro message from john [741004] bob received intro message from john [770008] joe received intro message from jill [779007] john received intro message from bob [736102] john received reply message from joe [741004] john received reply message from bob [770008] jill received intro message from sue [737001] bob received intro message from jill [816004] bob received reply message from john [736102] bob received intro message from sue [897005] jill received intro message from john [739000]
The time stamp of message sent and received should match . any help would be appreciated a code snippet performing the message sending and receiving would be highly appreciated . Thank you .
-module(exchange). -import(lists,[nth/2]). -export([start/0,for/2,for1/2,process/0]).
start()->
A=file:consult("calls.txt"),
T=element(2,A),
L=length(T),
%io:fwrite("~w",[L]),
for(L,T).
for(0,_)->
[];
for(L,Term) when L > 0 ->
S=nth(L,Term),
S1=element(1,S),
io:fwrite(" ~w~n",[S1]),
Q=element(2,S),
R=length(Q),
B=nth(1,Q),
for1 (R,Q),
Pid=spawn(exchange,process,[]),
register(S1,Pid),
S1 ! {sender, S1,R,Q},
for(L-1,Term).
for1(0,_)->
[];
for1(L1,Term1) when L1 >0 ->
S2=nth(L1,Term1),
process()->
receive
{sender, S1,R,Q}->
io:fwrite("~w received intro message from ",[S1]),
process()
end;
for1 (L1-1,Term1).