123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package main
- import (
- "errors"
- "log"
- "net"
- "os"
- "time"
- )
- func PostFind() string {
- file, err := os.ReadFile("finder.txt")
- if err != nil {
- log.Print(err)
- }
- addr, err := net.ResolveUDPAddr("udp", "239.255.255.250:1900")
- if err != nil {
- log.Print(err)
- }
- laddr, err := net.ResolveUDPAddr("udp", ":0")
- if err != nil {
- log.Print(err)
- }
-
-
-
- conn, err := net.ListenUDP("udp", laddr)
- if err != nil {
- log.Print(err)
- }
- defer conn.Close()
- conn.WriteTo(file, addr)
-
- log.Println("Posted Request for devices")
-
- conn.SetReadDeadline(time.Now().Add(time.Second * time.Duration(5)))
- buffer := make([]byte, 512)
- n, fromaddr, err := conn.ReadFrom(buffer)
- log.Printf("%d, %#v, %#v", n, fromaddr, err)
- var output string = string(buffer[0:n])
- log.Printf("GOT: [%s]", output)
-
- return output
- }
- func FileExists(path string) bool {
- _, err := os.Stat(path)
- return !errors.Is(err, os.ErrNotExist)
- }
|