[erlang-questions] should be a parallel tcp server, but can't connect to more than 1 client

Rapsey <>
Mon Jan 21 10:43:14 CET 2008


oh strange. It does work with telnet. Stupid me, I was trying it in a web
browser. Thank you for your help.




On Jan 21, 2008 10:36 AM, Bengt Kleberg <> wrote:

> Greetings,
>
> When run on Solaris9/Erts5.5.5.5 your program works for at least 2
> clients. Example:
>
> In xterm 1
> ws67042> telnet localhost 6011
> Trying 127.0.0.1...
> Connected to localhost.
> Escape character is '^]'.
> asd
> HTTP/1.1 200 OK
> Content-type: text/html
>
>
> <html><head></head><body>WOHOO<br>12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
>
> In xterm 2
> ws67042> telnet localhost 6011
> Trying 127.0.0.1...
> Connected to localhost.
> Escape character is '^]'.
> asd
> HTTP/1.1 200 OK
> Content-type: text/html
>
>
> <html><head></head><body>WOHOO<br>123456789101112131415161718192021222324252627
>
>
> bengt
> Those were the days...
>    EPO guidelines 1978: "If the contribution to the known art resides
>    solely in a computer program then the subject matter is not
>    patentable in whatever manner it may be presented in the claims."
>
>
> On 01/21/08 09:53, Rapsey wrote:
> > 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.
> >
> >
> > start() ->
> >     case gen_tcp:listen(6002, [binary, {packet, 0}, {active, true},
> > {reuseaddr, true}]) of
> >         {ok, Sock} ->
> >             spawn(fun() -> accept_conn(Sock) end);
> >         {error, Reason} -> {error, Reason}
> >     end.
> >
> >
> > accept_conn(LSock) ->
> >     case gen_tcp:accept(LSock) of
> >         {ok, Sock} ->
> >             spawn(fun() -> accept_conn(LSock) end),
> >             handle_conn(Sock);
> >         _ ->
> >             true
> >     end.
> >
> > % wait for http request from browser
> > handle_conn(Sock) ->
> >     receive
> >         {tcp, RecSock, Data} ->
> >             send_stream(RecSock, 0);
> >         {tcp_closed, _} ->
> >             true
> >     end.
> >
> > send_stream(Sock, N) when N == 0 ->
> >     gen_tcp:send(Sock, "HTTP/1.1 200 OK\r\nContent-type:
> > text/html\r\n\r\n<html><head></head><body>WOHOO<br>"),
> >     send_stream(Sock, N + 1);
> > send_stream(Sock, N) ->
> >     case gen_tcp:send(Sock, integer_to_list(N)) of
> >         ok ->
> >             timer:sleep(1000),
> >             send_stream(Sock, N + 1);
> >         Any ->
> >             true
> >     end.
> >
> >
> > thank you,
> > Sergej
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > erlang-questions mailing list
> > 
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080121/8902ea4d/attachment.html>


More information about the erlang-questions mailing list