2020
12-17
12-17
golang 实现tcp server端和client端,并计算RTT时间操作
server端代码:packagemainimport("fmt""net""log""os")funcmain(){addr:="0.0.0.0:8787"tcpAddr,err:=net.ResolveTCPAddr("tcp",addr)iferr!=nil{log.Fatalf("net.ResovleTCPAddrfail:%s",addr)//等价于printerr后,再os.Exit(1)}listener,err:=net.ListenTCP("tcp",tcpAddr)iferr!=nil{log.Fatalf("listen%sfail:%s",addr,err)}else{log.Println("rpclistening",addr)}fo...
继续阅读 >