usrpserv/usrp/client.go

37 lines
601 B
Go
Raw Permalink Normal View History

2024-05-24 23:07:40 +01:00
package usrp
import (
"log"
"net"
)
func NewClient(addr net.UDPAddr, laddr net.UDPAddr) Client {
var client Client
var err error
client.Sock, err = net.DialUDP("udp4", &laddr, &addr)
if err != nil {
log.Fatal(err)
}
return client
}
func (c *Client) WriteFrame(buffer []byte, n int) error {
n, err := c.Sock.Write(buffer[:n])
if err != nil || n == 0 {
return err
}
return nil
}
func (c *Client) Poll(buffer []byte, callback *func([]byte, int)) {
go func() {
for {
n, err := c.Sock.Read(buffer)
if err != nil {
log.Println(err)
}
(*callback)(buffer, n)
}
}()
}