Results 1 to 4 of 4

Thread: How to check if a given port is in use?

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    How to check if a given port is in use?

    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
    \m/\m/

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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.

  3. #3

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width