mirror of
https://github.com/genxium/DelayNoMore
synced 2025-10-09 08:36:52 +00:00
Drafted udp holepunching upsync pathway.
This commit is contained in:
31
udp_server_prac/main.go
Normal file
31
udp_server_prac/main.go
Normal file
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user