code: def open(self, host, port=0):
          
          self.eof = 0
          if not port:
              port = TELNET_PORT
          self.host = host
          self.port = port
          msg = "getaddrinfo returns an empty list"
          for res in socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM):
              af, socktype, proto, canonname, sa = res
              try:
                  self.sock = socket.socket(af, socktype, proto)
                  self.sock.settimeout(self.connect_timeout)
                  self.sock.connect(sa)
              except socket.error as msg_:
                  msg = '{} => telnet://{}:{}'.format(msg_, host, port)
                  if self.sock:
                      self.sock.close()
                  self.sock = None
                  continue
              break
          if not self.sock:
              raise socket.error(msg)
docs: Connect to a host.
  
          The optional second argument is the port number, which
          defaults to the standard telnet port (23).
  
          Don't try to reopen an already connected instance.