closing a listening socket by port number

Samuel Tardieu sam@REDACTED
Fri Nov 2 17:07:45 CET 2001


On  2/11, Willem Broekema wrote:

| I want to close a listening socket by its port number.

This does not work this way.

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

The TCP/IP stack does not allow that (you have to know the file descriptor
to close it; the FD is the only thing that you can manipulate at all).

You should use a supervisor (see OTP principles) or at least a linked
process: that process would close every socket object opened by the faulty
process.




More information about the erlang-questions mailing list