Results 1 to 4 of 4

Thread: [RESOLVED] [1.0/1.1] Validating a port number

  1. #1

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Resolved [RESOLVED] [1.0/1.1] Validating a port number

    Hi. I know how to validate a port number if it's in the min or max range. But how do you test for if the port number is being currently used?

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [1.0/1.1] Validating a port number

    I don't think you can unless you write a component that works at the level a firewall would.

    Ports can be used by multiple programs at once. You can have 1 FTP program connected to 3 seperate FTP server all utilizing Port 21.

    Why would you need this?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: [1.0/1.1] Validating a port number

    If you try to bind a TCP socket to a port that is already is associated with a TCP socket, it will fail. Same for UDP (I think). Of course, it might also fail for a myriad of other reasons.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  4. #4

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] Validating a port number

    i got the answer. Create a socket and bind onto the port using localhost as the ip address. If a SocketException is thrown then the port number is using. If ArgumentOutOfRangeException is thrown, then the port number is not between min and max.

    Jennifer.

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