BitTorrent HTTP、UDP tracker impl(50%)

This commit is contained in:
liwei committed 2019-05-17 19:07:10 +08:00
1 parent 808035094c
commit 41ff983b73
16 files changed
+600 -25

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
package main
import (
"fmt"
"net"
)
func main() {
conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 9981})
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("Local: <%s> \n", conn.LocalAddr().String())
data := make([]byte, 1024)
for {
n, remoteAddr, err := conn.ReadFromUDP(data)
if err != nil {
fmt.Printf("error during read: %s", err)
}
fmt.Printf("<%s> %s\n", remoteAddr, data[:n])
_, err = conn.WriteToUDP([]byte("world"), remoteAddr)
if err != nil {
fmt.Printf(err.Error())
}
}
}