Commit cb957416 authored by Administrator's avatar Administrator

Add new file

parent 8aedbf4f
Pipeline #597 passed with stage
in 1 second
package main
import (
"fmt"
"net"
"time"
)
func main() {
//connect server
time.Sleep(time.Second*5)
conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
IP: net.IPv4(127, 0, 0, 1),
Port: 9090,
})
if err != nil {
fmt.Printf("connect failed, err: %v\n", err)
return
}
for {
//send data
_, err = conn.Write([]byte("hello server!"))
if err != nil {
fmt.Printf("send data failed, err : %v\n", err)
return
}
//receive data from server
result := make([]byte, 4096)
n, remoteAddr, err := conn.ReadFromUDP(result)
if err != nil {
fmt.Printf("receive data failed, err: %v\n", err)
return
}
fmt.Printf("receive from addr: %v data: %v\n", remoteAddr, string(result[:n]))
time.Sleep(time.Second*1)
}
}
\ No newline at end of file
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