コード例 #1
0
ファイル: part8.go プロジェクト: smly/sandbox
func Listen() (l net.Listener, err error) {
	if *privateFlag {
		return net.Listen("tcp", fmt.Sprintf(":%d", *listenPort))
	} else {
		return util.Listen()
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: niiamon/whispering-gophers
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)
	}
}
コード例 #3
0
func main() {
	l, err := util.Listen()
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Listening on", l.Addr())
}
コード例 #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)
	}
}
コード例 #5
0
ファイル: main.go プロジェクト: niiamon/whispering-gophers
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)
	}
}
コード例 #6
0
ファイル: mesh_peer.go プロジェクト: tjdevries/cs_374_project
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)
	}
}
コード例 #7
0
ファイル: host.go プロジェクト: tjdevries/cs_374_project
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)
	}
}