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") } }
// 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 }
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) } }