examples/interact.go
branch20120108-close
changeset 68 d693ecc11f29
parent 63 c7f2edd25f4a
child 76 caa722ab8a0f
child 100 24231ff0016c
equal deleted inserted replaced
67:e8ad85bb6608 68:d693ecc11f29
     8 	"cjyar/xmpp"
     8 	"cjyar/xmpp"
     9 	"flag"
     9 	"flag"
    10 	"fmt"
    10 	"fmt"
    11 	"log"
    11 	"log"
    12 	"os"
    12 	"os"
    13 	"time"
       
    14 )
    13 )
    15 
    14 
    16 // Demonstrate the API, and allow the user to interact with an XMPP
    15 // Demonstrate the API, and allow the user to interact with an XMPP
    17 // server via the terminal.
    16 // server via the terminal.
    18 func main() {
    17 func main() {
    46 			fmt.Printf("s: %v\n", obj)
    45 			fmt.Printf("s: %v\n", obj)
    47 		}
    46 		}
    48 		fmt.Println("done reading")
    47 		fmt.Println("done reading")
    49 	}(c.In)
    48 	}(c.In)
    50 
    49 
    51 	time.Sleep(1e9 * 5)
    50 	p := make([]byte, 1024)
    52 	fmt.Println("Shutting down.")
    51 	for {
    53 	close(c.Out)
    52 		nr, _ := os.Stdin.Read(p)
    54 	time.Sleep(1e9 * 5)
    53 		if nr == 0 {
    55 	select {}
    54 			break
       
    55 		}
       
    56 		s := string(p)
       
    57 		stan, err := xmpp.ParseStanza(s)
       
    58 		if err == nil {
       
    59 			c.Out <- stan
       
    60 		} else {
       
    61 			fmt.Printf("Parse error: %v\n", err)
       
    62 			break
       
    63 		}
       
    64 	}
       
    65 	fmt.Println("done sending")
    56 }
    66 }