Maximum available ports to check after the specified port
971543
function createDefaultMiddleware(connect, options) {
					var middlewares = [];

					var directory = options.directory || options.base;
					// Serve static files.
					middlewares.push(serveStatic(options.base));
					// Make directory browse-able.
					middlewares.push(serveIndex(directory));
					return middlewares;
				}
799067
function checkPort(basePort, callback){
  return deasync(function(basePort, callback) {
    portfinder.basePort = basePort;
    portfinder.getPort(function (err, port) {
      callback(null, port);
    });
  })(basePort);
}
26308
def check_ports_on_br(self, bridge='br-ex', ports=['eth3']):
        
        LOG.info("RPC: check_ports_on_br bridge: %s, ports: %s" %
                 (bridge, ports))
        cmd = ['ovs-vsctl', 'list-ports', bridge]
        stdcode, stdout = agent_utils.execute(cmd, root=True)
        data = dict()
        if stdcode == 0:
            for port in ports:
                if port in stdout:
                    data[port] = True
                    stdout.remove(port)
                else:
                    data[port] = False
            return agent_utils.make_response(code=stdcode, data=data)
        # execute failed.
        message = stdout.pop(0)
        return agent_utils.make_response(code=stdcode,
                                         message=message)
803225
protected function findAvailablePort(int $port): ?int
	{
		$attempts = 0;

		while($attempts++ < static::MAX_PORTS_TO_TRY)
		{
			if(($socket = @fsockopen('localhost', $port, $errorNumber, $errorString, 0.1)) === false)
			{
				return $port;
			}

			fclose($socket);

			$port++;
		}

		return null;
	}
759000
public static int findAvailablePort(int maxRetries) {

        int retries = 0;
        int randomPort;
        boolean portAvailable;
        do {
            randomPort = randomPort();
            portAvailable = isPortAvailable(randomPort);
            retries++;
        } while (retries <= maxRetries && !portAvailable);
        assumeTrue("no open port found", portAvailable);
        return randomPort;
    }
113901
public static int getUsableLocalPort(int minPort, int maxPort) {
		for (int i = minPort; i <= maxPort; i++) {
			if (isUsableLocalPort(RandomUtil.randomInt(minPort, maxPort + 1))) {
				return i;
			}
		}

		throw new UtilException("Could not find an available port in the range [{}, {}] after {} attempts", minPort, maxPort, maxPort - minPort);
	}
373719
def wait_for_up(self, timeout=16, ports=None):
        
        port_list = []
        for port in ports:
            port_list.append(self.set_ports_list(port))
        t_end = time.time() + timeout
        ports_not_in_up = []
        ports_in_up = []
        while time.time() < t_end:
            # ixCheckLinkState can take few seconds on some ports when link is down.
            for port in port_list:
                call = self.api.call('ixCheckLinkState {}'.format(port))
                if call == '0':
                    ports_in_up.append("{}".format(port))
                else:
                    pass
            ports_in_up = list(set(ports_in_up))
            if len(port_list) == len(ports_in_up):
                return
            time.sleep(1)
        for port in port_list:
            if port not in ports_in_up:
                ports_not_in_up.append(port)
        raise TgnError('{}'.format(ports_not_in_up))
20338
def _get_port_range(range_str):
        
        if range_str == '*':
            return PortsRangeHelper.PortsRange(start=0, end=65535)

        s = range_str.split('-')
        if len(s) == 2:
            return PortsRangeHelper.PortsRange(start=int(s[0]), end=int(s[1]))

        return PortsRangeHelper.PortsRange(start=int(s[0]), end=int(s[0]))
572773
def check_serial_port(name):
    """"""
    try:
        cdc = next(serial.tools.list_ports.grep(name))
        return cdc[0]
    except StopIteration:
        msg = "device {} not found. ".format(name)
        msg += "available devices are: "
        ports = list(serial.tools.list_ports.comports())
        for p in ports:
            msg += "{},".format(text_type(p))
        raise ValueError(msg)
345085
def find_bound_ports(self, ports):
        """"""
        bound = []
        for port in ports:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            try:
                s.bind((port.ip if port.ip is not NotSpecified else "127.0.0.1", port.host_port))
            except socket.error as error:
                bound.append(port.host_port)
            finally:
                s.close()

        if bound:
            raise AlreadyBoundPorts(ports=bound)
1193636
private void handleDataAvailable() {
        InputStream inputStream = serialPort.getInputStream();
        try {
            while (inputStream.available() > 0) {
                byte inputByte = (byte) inputStream.read();

                if (inputByte == -1) {
                    log.error("Reached end of stream trying to read serial port.");
                    stop();
                    return;
                }

                Message message = configuration.getCommandParser().handleInputStream(inputByte, inputStream);

                if (message != null) {
                    log.debug("Routing message {}", message.getClass().getSimpleName());
                    routeMessage(message);
                }
            }
        } catch (IOException e) {
            log.error("IO Error reading from serial port. Closing connection.");
            e.printStackTrace();
            stop();
        }
    }
121193
def list_ports(self, retrieve_all=True, **_params):
        """"""
        # Pass filters in "params" argument to do_request
        return self.list('ports', self.ports_path, retrieve_all,
                         **_params)
1241420
public static boolean isPortAvailable(final int port) {

        try (ServerSocket tcp = new ServerSocket(port);
            DatagramSocket udp = new DatagramSocket(port)) {
            return tcp.isBound() && udp.isBound();
        } catch (Exception e) { //NOSONAR
            return false;
        }
    }
916333
def get_ports(self):
        ''
        return (self.bus.read_byte_data(self.address, self.STATUS_PORT0), self.bus.read_byte_data(self.address, self.STATUS_PORT1));
58200
def next_port
      port = @next_port
      @next_port -= 1
      @next_port = MAX_PORT if @next_port < MIN_PORT
      # check if the port is in use, if so get the next_port
      begin
        TCPSocket.new '127.0.0.1', port
      rescue Errno::EADDRINUSE
        next_port()
      rescue Errno::ECONNREFUSED
        port
      else
        next_port()
      end
    end
989971
def _get_valid_port(self, port):
        
        if '/' in port:
            port, protocol = port.split('/')
        else:
            protocol = 'tcp'

        try:
            int(port)
        except ValueError:
            raise ValueError("{0} isn't a valid port number.".format(port))

        if protocol not in ('tcp', 'udp'):
            raise ValueError("exposed ports only supports udp or tcp. {0} was passed".format(protocol))

        return "{0}/{1}".format(port, protocol)
459295
def pick_unused_port():
  
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.bind(('localhost', 0))
  addr, port = s.getsockname()
  s.close()
  return port