in reply to Checking if a port is allready used

The netstat command will show you the status of your network connections

netstat -nat

Will print out a list of all open TCP connections with ports (on Linux, check your local manpage if you're running a different *NIX, netstat tends to have subtly different syntax on the different variants). Since you're only communicating on the local host you'll likely only be interested in communications on 127.0.0.1

netstat -nlt

will print out a list of sockets your machine is listening on (and which are therefore blocked). For Linux you can also add "-p" to give you the processes listening on these sockets (if you're root).

BTW, if you're expecting to want to reuse the same port for a different process a lot, you should set SO_REUSEADDR when opening the socket for listening.

Update: Check out Net::Netstat::Wrapper for a Perl interface to netstat


There are ten types of people: those that understand binary and those that don't.