def _create_server(host, port):
    """
    Helper function.  Creates a listening socket on the designated
    host and port.  Modeled on the socket.create_connection()
    function.
    """

    exc = socket.error("getaddrinfo returns an empty list")
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
        af, socktype, proto, canonname, sa = res
        sock = None
        try:
            # Create the listening socket
            sock = socket.socket(af, socktype, proto)
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            sock.bind(sa)
            sock.listen(1024)
            return sock

        except socket.error as exc:
            # Clean up after ourselves
            if sock is not None:
                sock.close()

    # Couldn't create a listening socket
    raise exc
def _create_server ( host , port ) : exc = socket . error ( "getaddrinfo returns an empty list" ) for res in socket . getaddrinfo ( host , port , 0 , socket . SOCK_STREAM ) : af , socktype , proto , canonname , sa = res sock = None try : sock = socket . socket ( af , socktype , proto ) sock . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) sock . bind ( sa ) sock . listen ( 1024 ) return sock except socket . error as exc : if sock is not None : sock . close ( ) raise exc
Helper function.  Creates a listening socket on the designated
    host and port.  Modeled on the socket.create_connection()
    function.