mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-27 04:21:34 +00:00
43 lines
635 B
Go
43 lines
635 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"flag"
|
||
|
"fmt"
|
||
|
"net"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
port = flag.String("p", "12124", "Port number to listen on")
|
||
|
)
|
||
|
|
||
|
func e(err error) {
|
||
|
if err != nil {
|
||
|
fmt.Printf("Erroring out: %s\n", err)
|
||
|
os.Exit(1)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
flag.Parse()
|
||
|
|
||
|
// Bind to the port
|
||
|
bind, err := net.ResolveUDPAddr("0.0.0.0:" + *port)
|
||
|
e(err)
|
||
|
|
||
|
// Create listener
|
||
|
listener, err := net.ListenUDP("udp", bind)
|
||
|
e(err)
|
||
|
|
||
|
fmt.Printf("Listening to port %s...\n", *port)
|
||
|
for {
|
||
|
// read into a new buffer
|
||
|
buffer := make([]byte, 1024)
|
||
|
_, _, err := listener.ReadFrom(buffer)
|
||
|
e(err)
|
||
|
|
||
|
// log to standard output
|
||
|
fmt.Println(string(buffer))
|
||
|
}
|
||
|
}
|