CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2008
    Posts
    28

    Finding an avialable TCP Port

    Could someone point me to some sample C++ code that finds an available port on the local machine?

  2. #2
    Join Date
    Sep 2005
    Location
    London
    Posts
    208

    Re: Finding an avialable TCP Port

    It depends on the operating system.

    In UNIX for example you can use port 0 to allow your OS to automatically find and return the next available port. (In the dynamic port range).


    Hope it helps
    Doron Moraz

  3. #3
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Finding an avialable TCP Port

    I think your looking for a port scanner. This link looked interesting!

    http://www.planet-source-code.com/vb...=8010&lngWId=3

    Try googling for port scanner c++ and code.
    ahoodin
    To keep the plot moving, that's why.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Finding an avialable TCP Port

    Quote Originally Posted by Doron Moraz View Post
    In UNIX for example you can use port 0 to allow your OS to automatically find and return the next available port. (In the dynamic port range).
    The same is also in Windows.
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2008
    Posts
    28

    Re: Finding an avialable TCP Port

    Thank you all! Yes, binding to port 0 works just fine - I am doing this for win32 and win64 platforms... I wasnt familiar with socket programming at all, but still didnt take long to get this piece done. Thanks a lot!

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

Featured