How to build a dynamic list of TCP clients ?

info <>
Fri Nov 19 18:56:20 CET 2010


Hello,
In a TCP/IP gen_server I do:
Pid = spawn_link(... process_accept ...)

My first idea was to create a record and to insert the Pid just after the spawn_link:
Pid = spawn_link(... process_accept ...),
C = #clients(pid=Pid,name=0,s=Socket),   #name will be initialized by the process_accept
[C | ListClients];

Now I have my list of clients but a client can disappear (tcp_closed) and the list must be updated.
Is it a good approach or do you have better !

My objective is to give the possibility to send info to one client from another module by sending to the gen_server (handle_cast) the following command: send_to_client(Name,Message)
Next gen_server shall find the corresponding process and send the message by gen_tcp:send(S,Message)


J-Ph. Constantin
ITS3 Genève
www.its3.ch


More information about the erlang-questions mailing list