主备机

main
wangbin 2 months ago
parent 6f806744a2
commit 3bf587648a

@ -156,13 +156,21 @@ func ConnectToServer() {
log.Error("ConnectToServer:", r) log.Error("ConnectToServer:", r)
} }
}() }()
secondaryAddr := Common.LoadConfig().SeverData.BackUpServerIP + ":" + strconv.Itoa(ServerPort)
for { for {
c, err := net.Dial("tcp", Common.LoadConfig().SeverData.ServerIP+":"+strconv.Itoa(ServerPort)) c, err := net.Dial("tcp", Common.LoadConfig().SeverData.ServerIP+":"+strconv.Itoa(ServerPort))
if err != nil { if err != nil {
holmes.Errorf("连接失败,%v 后重试... 错误: %v\n", reconnectInterval, err) holmes.Errorf("连接失败,%v 后重试... 错误: %v\n", reconnectInterval, err)
time.Sleep(reconnectInterval)
continue // 主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 { onConnect := tao.OnConnectOption(func(conn tao.WriteCloser) bool {

Loading…
Cancel
Save