主备机

main
wangbin 2 months ago
parent 6f806744a2
commit 3bf587648a

@ -156,15 +156,23 @@ func ConnectToServer() {
log.Error("ConnectToServer:", r)
}
}()
secondaryAddr := Common.LoadConfig().SeverData.BackUpServerIP + ":" + strconv.Itoa(ServerPort)
for {
c, err := net.Dial("tcp", Common.LoadConfig().SeverData.ServerIP+":"+strconv.Itoa(ServerPort))
if err != nil {
holmes.Errorf("连接失败,%v 后重试... 错误: %v\n", reconnectInterval, err)
// 主IP失败时尝试备选IP
c, err = net.Dial("tcp", secondaryAddr)
if err != nil {
holmes.Errorf("备选IP连接失败%v 后重试主IP... 错误: %v\n", reconnectInterval, err)
time.Sleep(reconnectInterval)
continue
}
}
onConnect := tao.OnConnectOption(func(conn tao.WriteCloser) bool {
holmes.Infoln("on connect")
strall := (conn.(*tao.ClientConn)).Name()

Loading…
Cancel
Save