[erlang-questions] No timeout on connect

Gamoto <>
Sat Apr 4 14:38:16 CEST 2009


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 ?
John

-module(client).
-export([start/0,wait/1]).

start()->
    case gen_tcp:connect("localhost",1688,[binary, {packet, 0}],infinity) of
	{ok,Socket}->
	    io:format("Socket established~n"),
	    loop(Socket);
	{error,Reason} -> io:format("Error ! ~s~n",[Reason])
    end.

loop(Socket)->
    gen_tcp:send(Socket,"1234"),
    wait(4000),
loop(Socket).

wait(Timeout)->
    receive
after Timeout->
	0
end.




More information about the erlang-questions mailing list