Ejemplo n.º 1
0
func main() {
	opts := options.Server{}
	opts.Parse()

	server := zeroconf.NewServer("_goptyscreen._tcp.")
	bonjour, err := server.StartAnnounce(opts.Port)
	if err != nil {
		panic(err)
	}
	defer bonjour.Release()

	create_feed := make(chan pty_servers.PtyShare)
	delete_feed := make(chan string)
	ready_feed := make(chan int)
	view := pty_views.NewSupervisor()
	go view.CreateFeed(create_feed)
	go view.DeleteFeed(delete_feed)
	go view.WatchCommands(opts.Port)
	view.Refresh()

	rc_loader := pty_servers.NewRCLoader(ready_feed, opts.RCFilename)
	go rc_loader.OnReady()

	supervisor := pty_servers.NewSupervisor(create_feed, delete_feed)
	supervisor.Listen(opts.Port, ready_feed)
}
Ejemplo n.º 2
0
func StdoutChannel(port string, public_id string) (channel chan []byte) {
	channel = make(chan []byte)

	// start listening
	listener, unix_err := net.Listen("tcp", ":"+port)
	if unix_err != nil {
		panic(unix_err)
	}

	server := zeroconf.NewServer(go_pty_service)
	server.TxtRecords = map[string]string{
		public_id_key:  public_id,
		private_id_key: private_id,
	}

	string_port, _ := strconv.Atoi(port)
	bonjour, err := server.StartAnnounce(string_port)
	if err != nil {
		panic(err)
	}

	go func() {
		for {
			conn, _ := listener.Accept()
			go func() {
				for {
					bytes := make([]byte, READSIZE)
					read, err := conn.Read(bytes)
					if err != nil {
						close(channel)
						break
					}
					channel <- bytes[:read]
				}
			}()
		}
		defer bonjour.Release()
	}()

	return
}