[erlang-questions] No timeout on connect
Bengt Kleberg
bengt.kleberg@REDACTED
Mon Apr 6 17:13:08 CEST 2009
Greetings,
What kind of server are you running? If it has done listen, but not
accept, the timeout will be used. If there is no server, ie no listen,
then you will get an error.
bengt
On Mon, 2009-04-06 at 11:30 +0200, Gamoto wrote:
> I corrected my code as you said. connect is not blocking for me !
> After 5-6 seconds, I have the message "Error on connect ! Timeout
> What is wrong ?
>
> -module(client).
> -export([start/0,wait/1]).
>
> start()->
> case gen_tcp:connect("localhost",1688,[binary, {packet, 0}]) of
> {ok,Socket}->
> io:format("Socket established~n"),
> loop(Socket);
> {error,Reason} -> io:format("Error on connect ! ~s~n",[Reason])
> end.
>
> loop(Socket)->
> gen_tcp:send(Socket,"1234"),
> wait(10000),
> loop(Socket).
>
> wait(Timeout)->
> receive
> after Timeout->
> 0
> end.
>
>
>
> >connect() is always blocking, that's why you can provide a timeout.
> >
> >If, however, you actually mean a connect that will continue to retry
> >failed connections indefinitely, then no, you'd have to implement that
> >behaviour yourself.
> >
> >Cheers,
> >
> >B
> >
> >Gamoto wrote:
> >> I run on Windows server 2003
> >> There is no parameter for making a "blocking" connect ?
> >> John
> >>> Gamoto wrote:
> >>>> What is wrong in this code ? When I run it, without a listening server, after a few second, I have a timeout error !!
> >>>> infinity parameter is not correctly defined ?
> >>> Which OS and Erlang release are you using? When I try that on R12B-5
> >>> for both Linux and Windows it returns quickly as well, but the Reason is
> >>> 'econnrefused' which is what I'd expect to see when there's no server there.
> >>>
> >>> The timeout parameter is how long the connection attempt will wait for a
> >>> response of any kind, be it success, refusal or some other kind of
> >>> failure. Setting it to 'infinity' (the default, by the way, so you
> >>> don't need to explicitly set it) doesn't mean that it will keep retrying
> >>> a failed connection indefinitely.
> >>>
> >>> Cheers,
> >>>
> >>> Bernard
> >>>
> >>
> >
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list