for {
select {
case <-done:
if connectedIp != ip {
log.Infof("recv chan close:%v", ip)
listener.Close()
return
} else {
time.Sleep(time.Duration(4) * time.Second) //一定要大于下面的超时时间
done = make(chan int)
}
default:
if err = socket.SetReadDeadline(time.Now().Add(time.Duration(time.Second * 2))); err != nil
break
}
n, _, err := socket.ReadFromUDP(data)
if err != nil {
log.Infof(" read failed: %s", err)
break
}
connectedIp = ip
close(done)
}