network_supervisor skel compile now
[savant_proj.git] / src / network_supervisor.erl
blob1449529e6a6ce6fec0256260e1b9642c437119b0
1 -module(network_supervisor).
2 -export([start/4]).
4 start( address, port, game_pid, server_pid ) ->
5 {ok, Lsocket} = gen_tcp:listen(port, [binary]),
6 server( Lsocket ).
8 server( LSocket ) ->
9 case gen_tcp:accept(LSocket) of
10 {ok, socket} ->
11 loop(socket, game_pid, server_pid),
12 server(LSocket);
13 Other ->
14 io:format("accept returned"),
15 ok
16 end.
18 loop( socket, game_pid, server_pid )->
19 inet:setopts(socket,[{active,once}]),
20 receive
21 {tcp,socket,Data} ->
22 io:format( Data ),
23 gen_tcp:send("answer" , socket ),
24 loop( socket, game_pid, server_pid );
25 {tcp_closed,socket} ->
26 io:format("Socket ~w closed [~w]~n",[socket,self()]),
28 end.