mirror of
https://github.com/genxium/DelayNoMore
synced 2024-12-26 03:39:00 +00:00
32 lines
523 B
Go
32 lines
523 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
conn, err := net.ListenUDP("udp", &net.UDPAddr{
|
|
Port: 3000,
|
|
IP: net.ParseIP("127.0.0.1"),
|
|
})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
defer conn.Close()
|
|
fmt.Printf("server listening %s\n", conn.LocalAddr().String())
|
|
|
|
for {
|
|
message := make([]byte, 2046)
|
|
rlen, remote, err := conn.ReadFromUDP(message[:])
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
data := strings.TrimSpace(string(message[:rlen]))
|
|
fmt.Printf("received: %s from %s\n", data, remote)
|
|
}
|
|
}
|