Hi Jarrod,<br><br>Something like this might help you:<br><b><br>-define(MAX_TCP_CONNECTIONS, 1000).<br>-define(TCP_OPTIONS, [binary, {packet, 0}, {active, false}, {reuseaddr, true}, {backlog, ?MAX_TCP_CONNECTIONS}]).<br><br>
listen(Port, F) -><br> {ok, LSocket} = gen_tcp:listen(Port, ?TCP_OPTIONS),<br> accept(LSocket, F).<br><br>.............</b><br><br>Hope this is what you are looking for ...<br><br><div class="gmail_quote">On Tue, May 26, 2009 at 8:09 PM, Jarrod Roberson <span dir="ltr"><<a href="mailto:jarrod@vertigrated.com">jarrod@vertigrated.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I have the following code. How do I limit the number of connected clients.<br>
<br>
-module(linereceiver).<br>
<br>
-export([start/0]).<br>
<br>
sleep(T) -><br>
receive<br>
after T -><br>
true<br>
end.<br>
<br>
start() -><br>
spawn(fun() -><br>
start_parallel_server(3000),<br>
sleep(infinity)<br>
end).<br>
<br>
start_parallel_server(Port) -><br>
{ok, Listen} = gen_tcp:listen(Port, [binary,<br>
{packet,line},{reuseaddr, true},{active, true}]),<br>
spawn(fun() -> par_connect(Listen)end).<br>
<br>
par_connect(Listen) -><br>
{ok, Socket} = gen_tcp:accept(Listen),<br>
spawn(fun() -> par_connect(Listen) end),<br>
inet:setopts(Socket, [{packet, line}, list, {nodelay, true},<br>
{active, true}]),<br>
io:format("Connection Made!~n"),<br>
get_line(Socket).<br>
<br>
get_line(Socket) -><br>
receive<br>
{tcp, Socket, Line} -><br>
io:format("Received Line:~p~n", [Line]),<br>
get_line(Socket);<br>
{tcp_closed, Socket} -><br>
io:format("Connection Closed!~n"),<br>
void<br>
end.<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Regards,<br><br>Alin<br><br>