closing a listening socket by port number

Rodolphe Duge de Bernonville <>
Fri Nov 2 17:56:54 CET 2001

Willem Broekema a écrit :
> I want to close a listening socket by its port number.
> I have an application that should start a listening socket on a
> predefined port. Instead of return "{badmatch,{error,eaddrinuse}}",
> it should exit, or at least close the socket of, that process and
> take its place.
> Is it possible?

you should also do that in the module that open the socket : 

setsockopt with SO_REUSEADDR

example from different erl files :

   gen_tcp:listen(Port, [binary, {packet,cdr}, {reuseaddr,true}])
doc :

More information about the erlang-questions mailing list