Hi there,
I am trying to connect a device using UDP. Document of the device says, I must send a broadcast command using UDP port 4113 and must listen to replay on UDP port 4114.
When I test my code usin Linux nc command I get this error message:
invalid connection to [192.168.0.145] from (UNKNOWN) [192.168.0.100] 4114
My code:
command := []byte("%US1975**\r\n")
///
//
//
listenAddr, err := net.ResolveUDPAddr("udp4", "192.168.0.100:4114")
if err != nil {
return err
}
list, err := net.ListenUDP("udp4", listenAddr)
if err != nil {
return err
}
defer list.Close()
addr, err := net.ResolveUDPAddr("udp4", "192.168.0.255:4113")
if err != nil {
return err
}
_, err = list.WriteTo(command, addr)
if err != nil {
return err
}
reply := make([]byte, 236)
_, addrDevice, err := list.ReadFromUDP(reply)
if err != nil {
return err
}
fmt.Print("Device IP: ")
fmt.Println(addrDevice.IP.String())
fmt.Println("===================================================================")
fmt.Println(string(reply))
fmt.Println("===================================================================")