Exemple #1
0
func main() {

	// exporter, err := netchan.NewExporter("tcp", ":2345")
	exporter := netchan.NewExporter()
	err := exporter.ListenAndServe("tcp", ":2345")
	checkError(err)

	echoIn := make(chan string)
	echoOut := make(chan string)
	exporter.Export("echo-in", echoIn, netchan.Send)
	exporter.Export("echo-out", echoOut, netchan.Recv)
	for {
		fmt.Println("Getting from echoOut")
		s, ok := <-echoOut
		if !ok {
			fmt.Printf("Read from channel failed")
			os.Exit(1)
		}
		fmt.Println("received", s)

		fmt.Println("Sending back to echoIn")
		echoIn <- s
		fmt.Println("Sent to echoIn")
	}

}
Exemple #2
0
// InitExport creates a new Exporter on the IRC robot from which netchans can be created
func InitExport(bindAddr string) *netchan.Exporter {
	exp := netchan.NewExporter()
	go exp.ListenAndServe("tcp", bindAddr)
	go func() {
		for {
			exp.Drain(-1)
			time.Sleep(500000)
		}
	}()
	return exp
}
Exemple #3
0
func main() {

	exporter := netchan.NewExporter()
	err := exporter.ListenAndServe("tcp", ":2345")
	checkError(err)

	echo := make(chan string)
	exporter.Export("echo", echo, netchan.Send)
	for {
		sCount := strconv.Itoa(count)
		lock := make(chan string)
		go handleSession(exporter, sCount, lock)

		<-lock
		echo <- sCount
		count++
		exporter.Drain(-1)
	}
}