I am developing an irc bot and i am making the DCC part thing. I need to check if a given port is being used or not.
Is there any built in function to check that? Thanks
Printable View
I am developing an irc bot and i am making the DCC part thing. I need to check if a given port is being used or not.
Is there any built in function to check that? Thanks
Not sure if there's a built in function, but I've always tried to connect, and catch the exception if it's already in use.
Ha! Forgot about that.
But I tell you, here's the rub:
If you want your code to establish a connection, you better be prepared to handle anything that goes wrong. I mean, even if you check first to see if a port is in use, it does NOT mean (even if it's just a few milliseconds later) that that particular port is available.
So why bother to check the status before you attempt to connect? For robust code, you're going to have to handle the exception anyway. Might as well cut to the chase and try to connect anayway.
Just my opinion :)
Mike