5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-23 11:41:35 +00:00
matterbridge/vendor/github.com/alecthomas/log4go/examples/SimpleNetLogServer.go
2016-04-10 23:39:38 +02:00

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))
}
}