starting the foundation for multiple types of telemetry data
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package mockserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
const ProgramName = "TelemetryMockerserver"
|
||||
|
||||
type Transport interface {
|
||||
Send(data []byte) error
|
||||
Close() error
|
||||
}
|
||||
|
||||
type UDPTransport struct {
|
||||
Conn *net.UDPConn
|
||||
Addr *net.UDPAddr
|
||||
}
|
||||
|
||||
func NewUDPTransport(address string, port int) (*UDPTransport, error) {
|
||||
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", address, port))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conn, err := net.ListenUDP("udp", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &UDPTransport{Conn: conn, Addr: addr}, nil
|
||||
}
|
||||
|
||||
// Send will send a byte array of data trough the UDP server
|
||||
func (u *UDPTransport) Send(data []byte) (int, error) {
|
||||
return u.Conn.WriteToUDP(data, u.Addr)
|
||||
}
|
||||
|
||||
func (u *UDPTransport) Close() error {
|
||||
return u.Conn.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user