コード例 #1
0
ファイル: client_test.go プロジェクト: cluo/distributed-task
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)
	}
}
コード例 #2
0
ファイル: clienttest.go プロジェクト: cluo/distributed-task
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)
	}
}
コード例 #3
0
ファイル: runner.go プロジェクト: cluo/distributed-task
/*
	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()

	}
}