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