Commit 431d0881 authored by barnettZQG's avatar barnettZQG

change server

parent 1d574ae6
Pipeline #754 canceled with stages
...@@ -9,8 +9,8 @@ import ( ...@@ -9,8 +9,8 @@ import (
) )
func main() { func main() {
//address := "106.15.152.33:27065" address := "106.15.152.33:27065"
address := "127.0.0.1:8080" //address := "127.0.0.1:8080"
udpAddr, err := net.ResolveUDPAddr("udp", address) udpAddr, err := net.ResolveUDPAddr("udp", address)
con, err := net.DialUDP("udp", nil, udpAddr) con, err := net.DialUDP("udp", nil, udpAddr)
if err != nil { if err != nil {
...@@ -18,7 +18,9 @@ func main() { ...@@ -18,7 +18,9 @@ func main() {
} }
var n = 0 var n = 0
for { for {
con.Write([]byte(fmt.Sprintf("hello word %d", n))) message := fmt.Sprintf("hello word %d", n)
con.Write([]byte(message))
fmt.Printf("send:%s \n", message)
n++ n++
data := make([]byte, 1024) data := make([]byte, 1024)
n, _, err := con.ReadFromUDP(data) n, _, err := con.ReadFromUDP(data)
......
...@@ -21,7 +21,7 @@ func udpProcess(conn *net.UDPConn, index int) { ...@@ -21,7 +21,7 @@ func udpProcess(conn *net.UDPConn, index int) {
} }
str := string(data[:n]) str := string(data[:n])
fmt.Println("receive from client, data:" + str) fmt.Println("receive from client, data:" + str)
conn.WriteToUDP([]byte(fmt.Sprintf("receive %d", index)), rAddr) conn.WriteToUDP([]byte(fmt.Sprintf("server receive: %s", str)), rAddr)
<-limitChan <-limitChan
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment