[erlang-questions] Peername of a closed TCP socket

Tony Rogvall <>
Tue May 26 23:06:05 CEST 2009


You can try the inet option:
	{exit_on_close, false}
This will keep the port and the socket active so you can read  
statistics,
continue write data to a half open socket and possibly get the  
peername, if that is available
by the underlying operating system.

You must then call gen_tcp:close to terminate the port/socket

/Tony


On 26 maj 2009, at 17.39, Malcolm Dowse wrote:

> Hello,
>
> When a TCP client disconnects very soon after connecting to an  
> Erlang server, is there any reliable way of getting the client's  
> remote address?
>
> The inet:peername/1 function returns an error if the socket in  
> question has closed. As a result, I can't find any better solution  
> than to refactor the code so that inet:peername/1 is called as soon  
> as possible after the gen_tcp:accept/1.
>
> Thanks in advance,
>
> malcolm
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list