?
Solved

Finding a free port

Posted on 2000-01-10
1
Medium Priority
?
203 Views
Last Modified: 2008-02-01
Does anyone know the best way to find a free port for listening on?

At present I just start at a base port number and attempt bind() until it succeeds, incrementing the port number on each attempt.
0
Comment
Question by:alcockba
1 Comment
 
LVL 2

Accepted Solution

by:
kejin earned 400 total points
ID: 2340765
You only need set the binding port to 0 and let the system
to select a free port for you dynamically. Once the bind()
returned, you can use getsockname() on the socket to find
out what is the system selected port number.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses
Course of the Month4 days, 21 hours left to enroll

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question