mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-09 18:10:29 +00:00
BitTorrent HTTP、UDP tracker impl(50%)
This commit is contained in:
1 parent
808035094c
commit
41ff983b73
16 files changed
+600
-25
No files matched your search
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user