Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Excuse me, is that port taken?

by clintp (Curate)
on Aug 17, 2002 at 15:50 UTC ( #190873=note: print w/replies, xml ) Need Help??


in reply to Excuse me, is that port taken?

Two ways spring to mind. First, connect to the port yourself to see if anything is listening (untested):
use IO::Socket::INET; $sock=IO::Socket::INET->new(PeerAddr => 'machinename', PeerPort => $portnumber, Proto => 'tcp');
And if you get a "connection refused" there's probably no listener.

Another way is to bind the port yourself. If it's a low-numbered port, you'll have to be root.

use IO::Socket::INET; $sock=IO::Socket::INET->new(Listen => 1, LocalAddr => $interfaceaddres, LocalPort => $portnumber, ReuseAddr => 1, Proto => 'tcp');
If you don't get a "port already bound" error, then it's not bound.

If either of these fail, $sock will be undef and $! will have your error message.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://190873]
help
Chatterbox?
[marto]: good morning all
[Corion]: Hi marto ;)
[Corion]: I hope you're well ;)
[marto]: running late today, get to work and people are just sitting around. "can't delete file, quota exceeded"

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2017-01-24 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (203 votes). Check out past polls.