Ejemplo n.º 1
0
func main() {
	if len(os.Args) != 2 {
		fmt.Println("Usage: ", os.Args[0], "host:port")
		os.Exit(1)
	}
	service := os.Args[1]

	importer, err := netchan.Import("tcp", service)
	checkError(err)

	fmt.Println("Got importer")
	echo := make(chan string)
	importer.Import("echo", echo, netchan.Recv, 1)
	fmt.Println("Imported in")

	count := <-echo
	fmt.Println(count)

	echoIn := make(chan string)
	importer.Import("echoIn"+count, echoIn, netchan.Recv, 1)

	echoOut := make(chan string)
	importer.Import("echoOut"+count, echoOut, netchan.Send, 1)

	for n := 1; n < 10; n++ {
		echoOut <- "hello "
		s := <-echoIn
		fmt.Println(s, n)
	}
	close(echoOut)
	os.Exit(0)
}
Ejemplo n.º 2
0
func main() {
	if len(os.Args) != 2 {
		fmt.Println("Usage: ", os.Args[0], "host:port")
		os.Exit(1)
	}
	service := os.Args[1]

	importer, err := netchan.Import("tcp", service)
	checkError(err)
	fmt.Println("Got importer")
	echoIn := make(chan string)
	importer.Import("echo-in", echoIn, netchan.Recv, 1)
	fmt.Println("Imported in")
	echoOut := make(chan string)
	importer.Import("echo-out", echoOut, netchan.Send, 1)
	fmt.Println("Imported out")
	for n := 0; n < 10; n++ {
		echoOut <- "hello "
		s, ok := <-echoIn
		if !ok {
			fmt.Println("Read failure")
			break
		}
		fmt.Println(s, n)
	}
	close(echoOut)
	os.Exit(0)
}
Ejemplo n.º 3
0
// ImportFrom enables modules to establish two NetChan connections with the IRC robot
// so as to receive activity from IRC (Event) and to send actions to perform (Action).
func ImportFrom(hostname string, moduleUUID string) (chan Action, chan Event) {
	imp, err := netchan.Import("tcp", hostname)
	if err != nil {
		log.Fatalf("Can't import module %s: %v", moduleUUID, err)
	}
	chac := make(chan Action)
	err = imp.Import("actions", chac, netchan.Send, -1)
	if err != nil {
		log.Fatalf("Can't import module %s: %v", moduleUUID, err)
	}

	id := Action{Type: A_NEWMODULE, Data: moduleUUID}
	chac <- id

	// UGLY UGLY UGLY
	time.Sleep(100000000)

	chev := make(chan Event)
	err = imp.Import("events-"+moduleUUID, chev, netchan.Recv, -1)
	if err != nil {
		log.Fatalf("Can't import module %s: %v", moduleUUID, err)
	}
	return chac, chev
}