--- a/examples/interact.go Sun Jan 08 09:11:14 2012 -0700
+++ b/examples/interact.go Sun Jan 08 12:20:21 2012 -0700
@@ -10,7 +10,8 @@
"fmt"
"log"
"os"
- )
+ "time"
+)
// Demonstrate the API, and allow the user to interact with an XMPP
// server via the terminal.
@@ -28,7 +29,7 @@
if err != nil {
log.Fatalf("NewClient(%v): %v", jid, err)
}
- defer c.Close()
+ defer close(c.Out)
err = c.StartSession(true, &xmpp.Presence{})
if err != nil {
@@ -47,20 +48,9 @@
fmt.Println("done reading")
}(c.In)
- p := make([]byte, 1024)
- for {
- nr, _ := os.Stdin.Read(p)
- if nr == 0 {
- break
- }
- s := string(p)
- stan, err := xmpp.ParseStanza(s)
- if err == nil {
- c.Out <- stan
- } else {
- fmt.Printf("Parse error: %v\n", err)
- break
- }
- }
- fmt.Println("done sending")
+ time.Sleep(1e9 * 5)
+ fmt.Println("Shutting down.")
+ close(c.Out)
+ time.Sleep(1e9 * 5)
+ select {}
}