Exemple #1
0
func mainsever() {
	fmt.Println("starting client...")
	go gonet.ServerRun()
	gonet.ServerRead(func(msg string) {
		fmt.Println("from:", msg)
	})
	var input string
	fmt.Scanln(&input)
	fmt.Println("done")
}
Exemple #2
0
/*
	load config file & start client or server
	r define task, userfunc like map (define task itself),
	serverReduce server data reduce
*/
func Runner(r func(), userfunc UserExecuteFunc, serverReduce UserReduceFunc) {
	switch LocalConfig["ClientType"] {
	case "":
		log.Printf("config xml is wrong \n")
	case "client":
		log.Printf("starting client...\n")
		gonet.ClientInit()
		go r()
		// for {
		// 	var input string
		// 	if input == "stopclient" {
		// 		fmt.Scanln(&input)
		// 		fmt.Println("close client!")
		// 	}
		// }
		// gonet.ClientRead(func (msg string){
		// 	fmt.Printf("client read:", msg)
		// })
	case "server":
		log.Printf("starting server...\n")
		//init server reduce
		InitReducer(serverReduce)
		go manager(userfunc)
		go gonet.ServerRead(func(msg string) {
			log.Printf("recive msg:%v \n", msg)
			command := gocommand.GetCommand(msg)
			switch command.Method {
			case "reduce":
				//客户端发起规约
				ReduceFlag = true
			default:
				AddExcution(command.Method, command.Data, command.Type)
			}
		})
		gonet.ServerRun()

	}
}