5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-30 06:11:36 +00:00
matterbridge/vendor/github.com/alecthomas/log4go/examples/SimpleNetLogServer.go

43 lines
635 B
Go
Raw Normal View History

2016-04-10 21:39:38 +00:00
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))
}
}