mirror of https://github.com/cppla/ServerStatus
解决检查网络状态会造成程序崩溃的问题
parent
8a220653b1
commit
6e923f65f4
|
@ -238,29 +238,32 @@ var CM_ADDR = CU + ":" + strconv.Itoa(PORBEPORT)
|
||||||
func getNetworkStatus() {
|
func getNetworkStatus() {
|
||||||
defaulttimeout := 1 * time.Second
|
defaulttimeout := 1 * time.Second
|
||||||
count := 0
|
count := 0
|
||||||
conn , err := net.DialTimeout("tcp",CU_ADDR,defaulttimeout)
|
conn1 , err1 := net.DialTimeout("tcp",CU_ADDR,defaulttimeout)
|
||||||
defer conn.Close()
|
defer conn1.Close()
|
||||||
if err != nil {
|
if err1 != nil {
|
||||||
fmt.Println("Error try to connect China unicom :", err)
|
fmt.Println("Error try to connect China unicom :", err1)
|
||||||
count += 1
|
count += 1
|
||||||
|
conn1.Close()
|
||||||
} else {
|
} else {
|
||||||
conn.Close()
|
conn1.Close()
|
||||||
}
|
}
|
||||||
conn , err = net.DialTimeout("tcp", CT_ADDR,defaulttimeout)
|
conn2 , err2 := net.DialTimeout("tcp", CT_ADDR,defaulttimeout)
|
||||||
defer conn.Close()
|
defer conn2.Close()
|
||||||
if err != nil {
|
if err2 != nil {
|
||||||
fmt.Println("Error try to connect China telecom :", err)
|
fmt.Println("Error try to connect China telecom :", err2)
|
||||||
count += 1
|
count += 1
|
||||||
|
conn2.Close()
|
||||||
} else {
|
} else {
|
||||||
conn.Close()
|
conn2.Close()
|
||||||
}
|
}
|
||||||
conn , err = net.DialTimeout("tcp", CM_ADDR,defaulttimeout)
|
conn3 , err3 := net.DialTimeout("tcp", CM_ADDR,defaulttimeout)
|
||||||
defer conn.Close()
|
defer conn3.Close()
|
||||||
if err != nil {
|
if err3 != nil {
|
||||||
fmt.Println("Error try to connect China mobile :", err)
|
fmt.Println("Error try to connect China mobile :", err3)
|
||||||
count += 1
|
count += 1
|
||||||
|
conn3.Close()
|
||||||
} else {
|
} else {
|
||||||
conn.Close()
|
conn3.Close()
|
||||||
}
|
}
|
||||||
if count >= 2 {
|
if count >= 2 {
|
||||||
clientInfo.IpStatus = false
|
clientInfo.IpStatus = false
|
||||||
|
|
Loading…
Reference in New Issue