Tries to connect to the HTTP server at /status path
    and specified port to see if it responds successfully.

    :Args:
     - port - The port to connect.
180758
def is_url_connectable(port):
    
    try:
        from urllib import request as url_request
    except ImportError:
        import urllib2 as url_request

    try:
        res = url_request.urlopen("http://127.0.0.1:%s/status" % port)
        if res.getcode() == 200:
            return True
        else:
            return False
    except Exception:
        return False
1348435
def _do_connect(self):
        
        self.load_system_host_keys()
        if self.username is None or self.port is None:
            self._configure()
        try:
            self.connect(hostname=self.hostname,
                         port=self.port,
                         username=self.username,
                         key_filename=self.key_filename,
                         sock=self.proxy)
        except socket.error as e:
            raise GerritError("Failed to connect to server: %s" % e)

        try:
            version_string = self._transport.remote_version
            pattern = re.compile(r'^.*GerritCodeReview_([a-z0-9-\.]*) .*$')
            self.remote_version = _extract_version(version_string, pattern)
        except AttributeError:
            self.remote_version = None
258643
def connect(self, host, port):
        
        if not port and (host.find(':') == host.rfind(':')):
            i = host.rfind(':')
            if i >= 0:
                host, port = host[:i], host[i+1:]
            try: port = int(port)
            except ValueError:
                raise socket.error, "nonnumeric port"
        #if self.verbose > 0:
        #    print 'connect:', (host, port)
        msg = "getaddrinfo returns an empty list"
        self.sock = None
        for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
            af, socktype, proto, canonname, sa = res
            try:
                self.sock = socket.socket(af, socktype, proto)
                #if self.debuglevel > 0: print 'connect:', (host, port)
                self.sock.connect(sa)
            except socket.error, msg:
                #if self.debuglevel > 0: print 'connect fail:', (host, port)
                self.close()
                continue
            break
        if not self.sock:
            raise socket.error, msg
111250
def run(self):
        
        httpd = HTTPServer((self.host, self.port), self._Handler)
        sa = httpd.socket.getsockname()
        serve_message = "Serving HTTP on {host} port {port} (http://{host}:{port}/) ..."
        print(serve_message.format(host=sa[0], port=sa[1]))
        try:
            httpd.serve_forever()
        except KeyboardInterrupt:
            print("\nKeyboard interrupt received, exiting.")
            httpd.shutdown()
892690
def start(self, port):
        
        self.application = tornado.web.Application(self.views, 
                template_path=self.templatePath, 
                static_path=self.staticPath)
        self.application.listen(port)
        self.ioloop.start()
516739
def check_network_connection(server, port):
    '''
    
    '''
    logger = logging.getLogger(__name__)
    logger.debug("Checking network connection to server '%s'...", server)
    try:
        # see if we can resolve the host name -- tells us if there is
        # a DNS listening
        host = socket.gethostbyname(server)
        # connect to the host -- tells us if the host is actually
        # reachable
        sock = socket.create_connection((host, port), 2)
        sock.close()
    except Exception:  # pragma: no cover
        logger.debug("Network connection not working")
        return False
    logger.debug("Network connection working")
    return True
40165
def ports_str_check_failed(port_str):
    

    pattern = r'[^TU:0-9, \-]'
    if (
        re.search(pattern, port_str)
        or port_str.count('T') > 1
        or port_str.count('U') > 1
        or port_str.count(':') < (port_str.count('T') + port_str.count('U'))
    ):
        return True
    return False
930109
def isportopen(host, port):
    '''
    
    '''

    if not 1 <= int(port) <= 65535:
        return False

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    out = sock.connect_ex((sanitize_host(host), int(port)))

    return out
1066831
def check_port(helper, port):
    
    try:
        int(port)
    except ValueError:
        helper.exit(summary="Port (-p) must be a integer value.", exit_code=unknown, perfdata='')
881632
function isPortInUse(port) {
  _validatePortFormat(port);
  if (isPlatform('unix')) {
    if (isPlatform('linux') && fileExists('/proc/net')) {
      return _isPortInUseRaw(port);
    } else if (isInPath('netstat')) {
      return _isPortInUseNetstat(port);
    } else {
      throw new Error('Cannot check port status');
    }
  } else {
    throw new Error('Port checking not supported on this platform');
  }
}
202648
def start_server(self, addr='', port=8000):
        
        if self._multiprocess_on:
            raise SanicPrometheusError(
                "start_server can not be used when multiprocessing " +
                "is turned on")
        start_http_server(addr=addr, port=port)
408127
def with_port(self, port):
        
        # N.B. doesn't cleanup query/fragment
        if port is not None and not isinstance(port, int):
            raise TypeError("port should be int or None, got {}".format(type(port)))
        if not self.is_absolute():
            raise ValueError("port replacement is not allowed " "for relative URLs")
        val = self._val
        return URL(
            self._val._replace(
                netloc=self._make_netloc(
                    val.username, val.password, val.hostname, port, encode=False
                )
            ),
            encoded=True,
        )
1005265
def connect(self):
        if self._sStatus != 'opened':
            print "Netconf Connection: Invalid Status, Could not connect to %s:%s" % (self._sHost, self._uPort)
            sys.exit()
        # establish ssh connection
        if self._sType == 'ssh':
            # setup transport connection base on socket
            self._hSsh = paramiko.Transport(self._iSock) 
            try:
                self._hSsh.start_client()
            except paramiko.SSHException:
                print 'Netconf Connection: Connect negotiation failed'
                self._iSock.close()
                sys.exit()
            except:
                print 'Netconf Connection: Connect failed'
                try:
                    self._iSock.close()
                except:
                    pass
                sys.exit()
            # auth check
            if self._sPswd != '':
                try:
                    self._hSsh.auth_password(self._sUser, self._sPswd)
                except:
                    print "Netconf Connection: Auth SSH username/password fail"
                    self._iSock.close()
                    sys.exit()
            # open channel for netconf ssh subsystem
            try:
                self._hSshChn = self._hSsh.open_session()
                self._hSshChn.settimeout(5)
                self._hSshChn.set_name("netconf")
                self._hSshChn.invoke_subsystem("netconf")
                self._hSshChn.setblocking(1)
            except:
                print "Netconf Connection: Open SSH Netconf SubSystem fail"
                self._iSock.close()
                sys.exit()
        else:
            print "Netconf Connection: Unsupport Connection Type, Could not connect to %s:%s" % (self._sHost, self._uPort)
            sys.exit()

        self._sStatus = 'connected'

        
280806
def detect_port(port):
    ''''''
    socket_test = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    try:
        socket_test.connect(('127.0.0.1', int(port)))
        socket_test.close()
        return True
    except:
        return False
886258
def connect(self, host, port, name=None):
        
        client = self._clients.get(name)
        client.connect_to(host, port)
1243954
def connect(self):
        
        HTTPConnection.connect(self)
        self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
1246732
def listen(self):
        

        # Make sure we're in server mode
        if self.mode and self.mode != 'server':
            raise ValueError("%s is not in server mode" %
                             self.__class__.__name__)
        self.mode = 'server'

        # Obtain a listening socket
        serv = _create_server(self.host, self.port)

        # If we have too many errors, we want to bail out
        err_thresh = 0
        while True:
            # Accept a connection
            try:
                sock, addr = serv.accept()
            except Exception as exc:
                err_thresh += 1
                if err_thresh >= self.max_err_thresh:
                    LOG.exception("Too many errors accepting "
                                  "connections: %s" % str(exc))
                    break
                continue  # Pragma: nocover

            # Decrement error count on successful connections
            err_thresh = max(err_thresh - 1, 0)

            # Log the connection attempt
            LOG.info("Accepted connection from %s port %s" %
                     (addr[0], addr[1]))

            # And handle the connection
            eventlet.spawn_n(self.serve, self.connection_class(sock), addr)

        # Close the listening socket
        with utils.ignore_except():
            serv.close()