Ejemplo n.º 1
0
func pub() {
	id, _ := pastry.NodeIDFromBytes([]byte(strings.Repeat("pub", 20)))
	p := peter.New(id, "127.0.0.1", "127.0.0.1", "home", 1234)
	go p.Listen()
	reader := bufio.NewReader(os.Stdin)
	for {
		fmt.Printf("pub> ")
		text, err := reader.ReadString('\n')
		if err != nil {
			fmt.Println(err)
			return
		}

		text = text[:len(text)-1] // strip EOL
		if text == "" {
			continue
		}
		if text == "exit" {
			break
		}

		if err := p.Broadcast(topic, []byte(text)); err != nil {
			fmt.Println(err)
		}

	}

}
Ejemplo n.º 2
0
func sub() {
	id, _ := pastry.NodeIDFromBytes([]byte(strings.Repeat("sub", 20)))
	p := peter.New(id, "127.0.0.1", "127.0.0.1", "home", 1235)
	go p.Listen()
	defer p.Stop()

	err := p.Join("127.0.0.1", 1234)
	dieIfError(err)
	err = p.Subscribe(topic)
	dieIfError(err)
	time.Sleep(time.Hour)

}