All this program does is listen on a socket, spawn a new process on every connection and send a never ending stream of numbers to each client that connects to it. The problem is that once 1 client is connected, no one else can connect, even though a new acceptor process has been spawned.
<br><br><br>start() -><br> case gen_tcp:listen(6002, [binary, {packet, 0}, {active, true}, {reuseaddr, true}]) of<br> {ok, Sock} -><br> spawn(fun() -> accept_conn(Sock) end);<br> {error, Reason} -> {error, Reason}
<br> end.<br><br><br>accept_conn(LSock) -><br> case gen_tcp:accept(LSock) of<br> {ok, Sock} -><br> spawn(fun() -> accept_conn(LSock) end),<br> handle_conn(Sock);<br> _ ->
<br> true<br> end.<br><br>% wait for http request from browser<br>handle_conn(Sock) -><br> receive<br> {tcp, RecSock, Data} -><br> send_stream(RecSock, 0);<br> {tcp_closed, _} ->
<br> true<br> end.<br><br>send_stream(Sock, N) when N == 0 -><br> gen_tcp:send(Sock, "HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n<html><head></head><body>WOHOO<br>"),
<br> send_stream(Sock, N + 1);<br>send_stream(Sock, N) -><br> case gen_tcp:send(Sock, integer_to_list(N)) of<br> ok -><br> timer:sleep(1000),<br> send_stream(Sock, N + 1);<br> Any ->
<br> true<br> end.<br><br><br>thank you,<br>Sergej<br>