// Listen announces only on the Tailscale network.
// It will start the server if it has not been started yet.
Listen announces only on the Tailscale network.
It will start the server if it has not been started yet.
// Listen announces only on the Tailscale network . // It will start the server if it has not been started yet .
func (s *Server) Listen(network, addr string) (net.Listener, error) {
	host, port, err := net.SplitHostPort(addr)
	if err != nil {
		return nil, fmt.Errorf("tsnet: %w", err)
	}
	if err := s.Start(); err != nil {
		return nil, err
	}
	key := listenKey{network, host, port}
	ln := &listener{
		s:    s,
		key:  key,
		addr: addr,
		conn: make(chan net.Conn),
	}
	s.mu.Lock()
	if s.listeners == nil {
		s.listeners = map[listenKey]*listener{}
	}
	if _, ok := s.listeners[key]; ok {
		s.mu.Unlock()
		return nil, fmt.Errorf("tsnet: listener already open for %s, %s", network, addr)
	}
	s.listeners[key] = ln
	s.mu.Unlock()
	return ln, nil
}
func ( s * Server ) Listen ( network , addr string ) ( net . Listener , error ) { host , port , err := net . SplitHostPort ( addr ) if err != nil { return nil , fmt . Errorf ( " " , err ) } if err := s . Start ( ) ; err != nil { return nil , err } key := listenKey { network , host , port } ln := & listener { s : s , key : key , addr : addr , conn : make ( chan net . Conn ) , } s . mu . Lock ( ) if s . listeners == nil { s . listeners = map [ listenKey ] * listener { } } if _ , ok := s . listeners [ key ] ; ok { s . mu . Unlock ( ) return nil , fmt . Errorf ( " " , network , addr ) } s . listeners [ key ] = ln s . mu . Unlock ( ) return ln , nil }
Listen announces only on the Tailscale network.
Listen announces only on the Tailscale network .