Exemple #1
0
func TestClient(t *testing.T) {
	fmt.Println("starting client...")
	gonet.ClientInit()
	var msg = gonet.Message{Addr: "127.0.0.1:1256", Content: "haha"}
	fmt.Println("runging")
	for {
		fmt.Println("runging")
		gonet.Send(msg)
		time.Sleep(time.Second * 5)
	}
}
Exemple #2
0
func mainclient() {
	fmt.Println("starting client...")
	gonet.ClientInit()
	var msg = gonet.Message{Addr: "127.0.0.1:1256", Content: "haha"}
	gonet.Send(msg, nil)
	// time.Sleep(time.Second * 20)
	var input string
	for {
		fmt.Scanln(&input)
		fmt.Println("done")
		msg = gonet.Message{Addr: "127.0.0.1:1256", Content: input}
		gonet.Send(msg, nil)
	}
}
Exemple #3
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()

	}
}