multithread for dictateNode.

pull/37/head
Richard Liu 6 years ago
parent 6237990c14
commit 7600c9e3e7
  1. 40
      aws-experiment-launch/experiment/commander/main.go

@ -75,27 +75,31 @@ func dictateNodes(command string) {
port := "1" + config[1] // the port number of solider is "1" + node port
addr := strings.Join([]string{ip, port}, ":")
// creates client
conn, err := net.Dial("tcp", addr)
if err != nil {
log.Println(err)
return
}
defer conn.Close()
go dictateNode(addr, command)
}
}
// send command
_, err = conn.Write([]byte(command))
if err != nil {
log.Printf("Failed to send command to %s", addr)
return
}
log.Printf("Send: %s", command)
func dictateNode(addr string, command string) {
// creates client
conn, err := net.Dial("tcp", addr)
if err != nil {
log.Println(err)
return
}
defer conn.Close()
// read response
buff := make([]byte, 1024)
n, _ := conn.Read(buff)
log.Printf("Receive from %s: %s", addr, buff[:n])
// send command
_, err = conn.Write([]byte(command))
if err != nil {
log.Printf("Failed to send command to %s", addr)
return
}
log.Printf("Send: %s", command)
// read response
buff := make([]byte, 1024)
n, _ := conn.Read(buff)
log.Printf("Receive from %s: %s", addr, buff[:n])
}
func hostConfigFile() {

Loading…
Cancel
Save