Commit 02b2495d authored by szh's avatar szh

localip 实时获取 防止树莓派ip变化,udp发送不成功

parent 1f091ab1
...@@ -69,6 +69,15 @@ func main() { ...@@ -69,6 +69,15 @@ func main() {
func broadcast() { func broadcast() {
var pai pai_service.Pai
send := "hello world"
ok := pai.GetConfig()
if ok {
send = pai.Serial
}
for {
//ip 会变化
ip,err := util.GetLocalIP() ip,err := util.GetLocalIP()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
...@@ -87,17 +96,8 @@ func broadcast() { ...@@ -87,17 +96,8 @@ func broadcast() {
conn, err := net.DialUDP("udp", &laddr, &raddr) conn, err := net.DialUDP("udp", &laddr, &raddr)
if err != nil { if err != nil {
log.Println(err.Error()) log.Println(err.Error())
return
} }
var pai pai_service.Pai _, err = conn.Write([]byte(send))
send := "hello world"
ok := pai.GetConfig()
if ok {
send = pai.Serial
}
for {
_, err := conn.Write([]byte(send))
if err != nil{ if err != nil{
fmt.Println(err) fmt.Println(err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment