func exportSend(exp *netchan.Exporter) { ch := make(chan value) exp.Export("exportedSend", ch, netchan.Send, new(value)) for i := 0; i < count; i++ { ch <- value{23 + i, "hello"} } }
// Listen uses the given Exporter to listen on the given service name. // It uses a set of netchan channels, all prefixed with that name. // The connections returned by the Listener have underlying type *Conn. // This can be used to gain access to the underlying channels. func Listen(exp *netchan.Exporter, service string) (net.Listener, error) { r := &netchanListener{ exp: exp, name: service, conns: make(chan net.Conn), closed: make(chan bool), } // Create the auxilliary channel and export it. clientNames := make(chan string) err := exp.Export(service, clientNames, netchan.Send) if err != nil { return nil, err } go func() { for i := 0; ; i++ { clientName := fmt.Sprintf("%s.%d", service, i) r.exporter(clientName) select { case clientNames <- clientName: case <-r.closed: return } } }() return r, nil }
func server(name string, exp *netchan.Exporter, ready chan bool, ready2 chan bool) { l := log.New(os.Stdout, fmt.Sprintf("server [%v]: ", name), 0) ch_send := make(chan chan_type) err := exp.Export(name, ch_send, netchan.Send) if err != nil { l.Fatal(err) } // I am set up ready <- true // Wait for all other instances of me to be set up <-ready2 ch_send <- "YOU GOT SERVED" ch_send <- "<3" close(ch_send) }