examples/interact.go
changeset 6 8e425e340ca1
parent 4 a8fbec71a194
child 9 4fe926b03827
equal deleted inserted replaced
5:faef59c8db05 6:8e425e340ca1
     5 package main
     5 package main
     6 
     6 
     7 import (
     7 import (
     8 	"cjyar/xmpp"
     8 	"cjyar/xmpp"
     9 	"flag"
     9 	"flag"
       
    10 	"fmt"
    10 	"log"
    11 	"log"
    11 	"os"
    12 	"os"
    12 	)
    13 	)
    13 
    14 
    14 // 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
    26 	c, err := xmpp.NewClient(&jid, *pw)
    27 	c, err := xmpp.NewClient(&jid, *pw)
    27 	if err != nil {
    28 	if err != nil {
    28 		log.Fatalf("NewClient(%v): %v", jid, err)
    29 		log.Fatalf("NewClient(%v): %v", jid, err)
    29 	}
    30 	}
    30 	defer c.Close()
    31 	defer c.Close()
       
    32 
       
    33 	go func(ch <-chan interface{}) {
       
    34 		for obj := range ch {
       
    35 			fmt.Printf("s: %v\n", obj)
       
    36 		}
       
    37 		fmt.Println("done reading")
       
    38 	}(c.In)
       
    39 
       
    40 	ch := make(chan interface{})
       
    41 	go xmpp.ReadXml(os.Stdin, ch, false)
       
    42 	for x := range ch {
       
    43 		fmt.Printf("c: %v", x)
       
    44 		c.Out <- x
       
    45 	}
       
    46 	fmt.Println("done sending")
    31 }
    47 }