code: def _connect(self, target, listen, udp, ipv6, retry):
          
          ty = socket.SOCK_DGRAM if udp else socket.SOCK_STREAM
          fam = socket.AF_INET6 if ipv6 else socket.AF_INET
          self.sock = socket.socket(fam, ty)
          if listen:
              self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
              self.sock.bind(target)
              if not udp:
                  self.sock.listen(1)
                  conn, addr = self.sock.accept()
                  self.sock.close()
                  self.sock = conn
                  self.peer = addr
              else:
                  self.buf, self.peer = self.sock.recvfrom(1024)
                  self.sock.connect(self.peer)
                  self._log_recv(self.buf, False)
              if self.verbose:
                  self._print_verbose('Connection from %s accepted' % str(self.peer))
          else:
              while True:
                  try:
                      self.sock.connect(target)
                  except (socket.gaierror, socket.herror) as exc:
                      raise NetcatError('Could not connect to %r: %r' \
                              % (target, exc))
                  except socket.error as exc:
                      if retry:
                          time.sleep(0.2)
                      else:
                          raise NetcatError('Could not connect to %r: %r' \
                                  % (target, exc))
                  else:
                      break
              self.peer = target
docs: Takes target/listen/udp/ipv6 and sets self.sock and self.peer