Beispiel #1
0
func Listen() (l net.Listener, err error) {
	if *privateFlag {
		return net.Listen("tcp", fmt.Sprintf(":%d", *listenPort))
	} else {
		return util.Listen()
	}
}
Beispiel #2
0
func main() {
	flag.Parse()

	l, err := util.Listen()
	if err != nil {
		log.Fatal(err)
	}
	self = l.Addr().String()
	log.Println("Listening on", self)

	if *peerAddr != "" {
		go dial(*peerAddr)
	}
	go readInput()

	go func() {
		for {
			c, err := l.Accept()
			if err != nil {
				log.Fatal(err)
			}
			go serve(c)
		}
	}()

	http.HandleFunc("/", rootHandler)
	http.Handle("/log", websocket.Handler(logHandler))
	err = http.ListenAndServe(*httpAddr, nil)
	if err != nil {
		log.Fatal(err)
	}
}
func main() {
	l, err := util.Listen()
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Listening on", l.Addr())
}
Beispiel #4
0
func main() {
	flag.Parse() // To parse the util package's -master flag.
	l, err := util.Listen()
	if err != nil {
		log.Fatal(err)
	}
	err = util.RegisterPeer(l.Addr().String())
	if err != nil {
		log.Fatal(err)
	}
}
Beispiel #5
0
func main() {
	flag.Parse()

	l, err := util.Listen()
	if err != nil {
		log.Fatal(err)
	}
	self = l.Addr().String()
	log.Println("Listening on", self)

	go dial(*peerAddr)

	for {
		c, err := l.Accept()
		if err != nil {
			log.Fatal(err)
		}
		go serve(c)
	}
}
Beispiel #6
0
func main() {
	// Parse the items sent in by command line
	flag.Parse()

	var self_client Client
	self_client.SetDefaults()

	// Debug print statement to show that we have initialize the client correctly
	fmt.Println("Self ID is", self_client.ID, ", Addr is:", self_client.Addr, ", Hostfound is:", self_client.HostFound)

	// Get our IP address
	l, err := util.Listen()
	if err != nil {
		log.Fatal(err)
	}
	self_client.Addr = l.Addr().String()

	fmt.Println("Self ID is", self_client.ID, ", Addr is:", self_client.Addr, ", Hostfound is:", self_client.HostFound)

	// Dial the address of the host
	go dial(*hostAddr)

	// Make sure that it is the host
	go checkIfHost()

	// Send something to the host here

	// Read something back from the host here
	go readInput()

	for {
		c, err := l.Accept()
		if err != nil {
			log.Fatal(err)
		}
		go serve(c)
	}
}
Beispiel #7
0
func main() {
	// Parse the items sent in by command line
	flag.Parse()

	// Get our IP address
	l, err := util.Listen()
	if err != nil {
		log.Fatal(err)
	}
	self = l.Addr().String()
	log.Println("Listening on", self)

	// Dial the address of the peer, however this is unnecessary because we are the host
	// go dial(*peerAddr)
	// go readInput()

	for {
		c, err := l.Accept()
		if err != nil {
			log.Fatal(err)
		}
		go serve(c)
	}
}