'open_socket()
Open socket choosing first address family available.'

def open_socket(self):

    msg = ((-1), 'could    not    open    socket')
    for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM):
        (af, socktype, proto, canonname, sa) = res
        try:
            s = socket.socket(af, socktype, proto)
        except socket.error as m:
            msg = m
            continue
        try:
            for i in (0, 1):
                try:
                    s.connect(sa)
                    break
                except socket.error as m:
                    msg = m
                    if ((len(msg.args) < 2) or (msg.args[0] != errno.EINTR)):
                        raise
            else:
                raise socket.error(msg)
        except socket.error as m:
            msg = m
            s.close()
            continue
        break
    else:
        raise socket.error(msg)
    return s
