标签:ror read imp pac server make error nil cli
server.go
package main
import (
"fmt"
"net"
)
func main() {
listener,err :=net.Listen("tcp","127.0.0.1:8080")
if err !=nil{
fmt.Println(err.Error())
return
}
defer listener.Close()
conn,err := listener.Accept()
if err != nil{
fmt.Println(err.Error())
return
buff := make([]byte,1024)
n,err:= conn.Read(buff)
if err !=nil{
fmt.Println(err)
return
}
fmt.Println("content=",string(buff[:n]))
defer conn.Close()
}
}
client.go
package main
import (
"fmt"
"net"
)
func main() {
conn,err := net.Dial("tcp","127.0.0.1:8000")
if err !=nil{
fmt.Println(err)
}
defer conn.Close()
conn.Write([]byte("are you ok"))
}
标签:ror read imp pac server make error nil cli
原文地址:https://www.cnblogs.com/paulversion/p/11617339.html