From ab0935816d5c15781c78c2524b776e77983eac8e Mon Sep 17 00:00:00 2001 From: esrrhs Date: Thu, 20 Dec 2018 14:15:36 +0800 Subject: [PATCH] fix --- client.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/client.go b/client.go index 9f930c1..bdd3a8f 100644 --- a/client.go +++ b/client.go @@ -112,16 +112,12 @@ 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.showNet() - case <-intervalPing.C: p.ping() + p.showNet() case r := <-recv: p.processPacket(r) } @@ -231,10 +227,12 @@ func (p *Client) checkTimeoutConn() { } func (p *Client) ping() { - now := time.Now() - b, _ := now.MarshalBinary() - sendICMP(*p.conn, p.ipaddrServer, p.targetAddr, "", (uint32)(PING), b, p.sproto, p.rproto) - fmt.Printf("ping %s %s %d %d\n", p.addrServer, now.String(), p.sproto, p.rproto) + if p.sendPacket == 0 && p.recvPacket == 0 { + now := time.Now() + b, _ := now.MarshalBinary() + sendICMP(*p.conn, p.ipaddrServer, p.targetAddr, "", (uint32)(PING), b, p.sproto, p.rproto) + fmt.Printf("ping %s %s %d %d\n", p.addrServer, now.String(), p.sproto, p.rproto) + } } func (p *Client) showNet() {