From 5100dcec6e1dd53a41e3c45d7291ccc8c4bb9d2d Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 14 Jun 2016 09:07:35 -0700 Subject: [PATCH] update hosts example --- examples/hosts/main.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/hosts/main.go b/examples/hosts/main.go index 16c6de493..f92be28b3 100644 --- a/examples/hosts/main.go +++ b/examples/hosts/main.go @@ -21,6 +21,12 @@ import ( context "golang.org/x/net/context" ) +func init() { + // Disable secio for this demo + // This makes testing with javascript easier + conn.EncryptConnections = false +} + // create a 'Host' with a random peer to listen on the given address func makeDummyHost(listen string) (host.Host, error) { addr, err := ma.NewMultiaddr(listen) @@ -47,7 +53,7 @@ func makeDummyHost(listen string) (host.Host, error) { } func main() { - conn.EncryptConnections = false + listenF := flag.Int("l", 0, "wait for incoming connections") target := flag.String("d", "", "target peer to dial") flag.Parse() @@ -60,6 +66,7 @@ func main() { } message := []byte("hello libp2p!") + // Set a stream handler on host A ha.SetStreamHandler("/hello/1.0.0", func(s net.Stream) { defer s.Close() @@ -68,10 +75,8 @@ func main() { }) if *target == "" { - log.Println("listening on for connections...") - for { - time.Sleep(time.Hour) - } + log.Println("listening for connections...") + select {} // hang forever } a, err := ipfsaddr.ParseString(*target)