code: def socks_endpoint(self, reactor, port=None):
          
  
          if len(self.SocksPort) == 0:
              raise RuntimeError(
                  "No SOCKS ports configured"
              )
  
          socks_config = None
          if port is None:
              socks_config = self.SocksPort[0]
          else:
              port = str(port)  # in case e.g. an int passed in
              if ' ' in port:
                  raise ValueError(
                      "Can't specify options; use create_socks_endpoint instead"
                  )
  
              for idx, port_config in enumerate(self.SocksPort):
                  # "SOCKSPort" is a gnarly beast that can have a bunch
                  # of options appended, so we have to split off the
                  # first thing which *should* be the port (or can be a
                  # string like 'unix:')
                  if port_config.split()[0] == port:
                      socks_config = port_config
                      break
          if socks_config is None:
              raise RuntimeError(
                  "No SOCKSPort configured for port {}".format(port)
              )
  
          return _endpoint_from_socksport_line(reactor, socks_config)
docs: Returns a TorSocksEndpoint configured to use an already-configured
          SOCKSPort from the Tor we're connected to. By default, this
          will be the very first SOCKSPort.
  
          :param port: a str, the first part of the SOCKSPort line (that
              is, a port like "9151" or a Unix socket config like
              "unix:/path". You may also specify a port as an int.
  
          If you need to use a particular port that may or may not
          already be configured, see the async method
          :meth:`txtorcon.TorConfig.create_socks_endpoint`