func getCommandConnection(leader string, agentName string) (net.Conn, error) { l := client.NewNameServiceAgent(leader) // looking for the agentName var target string for { locations := l.Find(agentName) if len(locations) > 0 { target = locations[0] } if target != "" { break } else { time.Sleep(time.Second) print("z") } } // connect to a TCP server network := "tcp" raddr, err := net.ResolveTCPAddr(network, target) if err != nil { return nil, fmt.Errorf("Fail to resolve %s:%v", target, err) } // println("dial tcp", raddr.String()) conn, err := net.DialTCP(network, nil, raddr) if err != nil { return nil, fmt.Errorf("Fail to dial %s:%v", raddr, err) } return conn, err }
func (rc *ReceiveChannel) findTarget() (target string) { l := client.NewNameServiceAgent(rc.Leader) for { locations := l.Find(rc.name) if len(locations) > 0 { target = locations[rand.Intn(len(locations))] } if target != "" { break } else { time.Sleep(time.Second) // print("z") } } return }