From 3241a745e71f45260f85a01c565cd60b111ac92d Mon Sep 17 00:00:00 2001 From: esrrhs Date: Wed, 19 Dec 2018 15:58:58 +0800 Subject: [PATCH] add --- client.go | 8 ++++++-- server.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index b9d0847..b095cd3 100644 --- a/client.go +++ b/client.go @@ -112,12 +112,16 @@ func (p *Client) Run() { interval := time.NewTicker(time.Second) defer interval.Stop() + intervalPing := time.NewTicker(time.Second * 10) + defer interval.Stop() + for { select { case <-interval.C: p.checkTimeoutConn() - p.ping() p.showNet() + case <-intervalPing.C: + p.ping() case r := <-recv: p.processPacket(r) } @@ -230,7 +234,7 @@ func (p *Client) ping() { } func (p *Client) showNet() { - fmt.Printf("send %dPacket/s %dKB/s recv %dPacket/s %dKB/s\n", p.sendPacket, p.sendPacket/1024, p.recvPacket, p.recvPacket/1024) + fmt.Printf("send %dPacket/s %dKB/s recv %dPacket/s %dKB/s\n", p.sendPacket, p.sendPacketSize/1024, p.recvPacket, p.recvPacketSize/1024) p.sendPacket = 0 p.recvPacket = 0 p.sendPacketSize = 0 diff --git a/server.go b/server.go index 103321c..cc2cb24 100644 --- a/server.go +++ b/server.go @@ -169,7 +169,7 @@ func (p *Server) checkTimeoutConn() { } func (p *Server) showNet() { - fmt.Printf("send %dPacket/s %dKB/s recv %dPacket/s %dKB/s\n", p.sendPacket, p.sendPacket/1024, p.recvPacket, p.recvPacket/1024) + fmt.Printf("send %dPacket/s %dKB/s recv %dPacket/s %dKB/s\n", p.sendPacket, p.sendPacketSize/1024, p.recvPacket, p.recvPacketSize/1024) p.sendPacket = 0 p.recvPacket = 0 p.sendPacketSize = 0