Example #1
0
func Server(stop chan int) {
	exp := netchan.NewExporter()

	errNE := exp.ListenAndServe("tcp", ":9999")
	handleError(errNE)
	channelBobReceive := make(chan string)
	errRE := exp.Export("AliceToBob", channelBobReceive, netchan.Recv)
	handleError(errRE)

	for i := 0; i < 100; i++ {
		<-channelBobReceive
		//fmt.Printf("%i %s\n", i, <-channelBobReceive)
	}
	stop <- 1
}
Example #2
0
//Creates a new LocalWorker. If export is true, than
//the LocalWorker exports its input channel in the network address
//provided by workerAddr
func NewLocalWorker(mode, hostAddr *string) (w *LocalWorker) {
	defer func() {
		if e := recover(); e != nil {
			log.Fatalf("Panic starting the worker!!!!", e)
		}
	}()
	w = new(LocalWorker)
	w.channel = make(chan Task, 10)
	w.mode = mode
	//exports the channels
	if *mode == WORKER {
		e := netchan.NewExporter()
		e.Export("workerChannel", w.channel, netchan.Recv)
		e.ListenAndServe("tcp", *hostAddr)
	}
	return
}
Example #3
0
//New Master returned. If mode is master, attempts to export the
//master channel for workers.
//Timout is also considere.
func NewMaster(mode, hostAddr *string, timeout int64) *Master {
	log.Print("Starting Master...")
	masterChan := make(chan WorkSummary, 10)
	m := new(Master)
	m.session = newSession(timeout)

	log.Printf("TEST SESSION %v", m.session)
	if *mode == MASTER {
		m.exptr = netchan.NewExporter()
		m.exptr.Export("masterChannel", masterChan, netchan.Recv)
		m.exptr.ListenAndServe("tcp", *hostAddr)
	}

	m.channel = masterChan
	m.mode = mode
	m.summary = &Summary{Min: -1}
	return m

}
Example #4
0
func main() {
	exp := netchan.NewExporter()

	errNE := exp.ListenAndServe("tcp", ":9999")
	handleError(errNE)

	channelBobSend := make(chan []*big.Int)
	channelBobReceive := make(chan []*big.Int)

	errSE := exp.Export("BobToAlice", channelBobSend, netchan.Send)
	handleError(errSE)

	errRE := exp.Export("AliceToBob", channelBobReceive, netchan.Recv)
	handleError(errRE)

	stop := make(chan int)

	go bob(channelBobReceive, channelBobSend, stop)
	<-stop
}