Git Product home page Git Product logo

Comments (11)

sparrc avatar sparrc commented on August 15, 2024

Sorry I'm not sure I understand, can you explain what you are trying to accomplish?

from ping.

Lvzhenqian avatar Lvzhenqian commented on August 15, 2024
func worker(addr string, count int) *ping.Statistics {
	pinger, CreateErr := ping.NewPinger(addr)
	if CreateErr != nil {
		panic(CreateErr)
	}
	pinger.SetPrivileged(true)
	pinger.Count = count
	pinger.OnRecv = func(pkt *ping.Packet) {
		fmt.Printf("%d bytes from %s: icmp_seq=%d time=%v\n",
			pkt.Nbytes, pkt.IPAddr, pkt.Seq, pkt.Rtt)
	}
	pinger.Run()
	return pinger.Statistics()
}

func main() {
	s := worker("52.34.112.193",10)
	fmt.Println(s)
}

This is my code, and when I tested it, I found that when the network was not stable enough to recv a packet or two, the count never met and quit the ping program

from ping.

Lvzhenqian avatar Lvzhenqian commented on August 15, 2024

Sorry I'm not sure I understand, can you explain what you are trying to accomplish?

It should exit the ping program after sending 10 packets

from ping.

sparrc avatar sparrc commented on August 15, 2024

You can use the Timeout parameter on the Pinger struct, does that work for you?

see https://godoc.org/github.com/sparrc/go-ping#Pinger

from ping.

Lvzhenqian avatar Lvzhenqian commented on August 15, 2024
case <-interval.C:
if p.Count > 0 && p.PacketsSent >= p.Count {
       // before is continue , that is why can't exit pinger
	close(p.done)
	wg.Wait()
}

Timeout this parameter does not meet my requirements...en

from ping.

sparrc avatar sparrc commented on August 15, 2024

Fundamentally the pinger "count" option waits for responses after it sends out pings so it can't simply exit immediately after sending 10 pings. This is consistent with the BSD implementation of ping but I suppose it's not consistent with the GNU implementation.

One option would be to make it consistent with the GNU implementation, although I think the BSD implementation seems more reasonable.

Another option would be to implement a per-ping timeout (-W in GNU and BSD ping) in addition to the current overall timeout, though I'm not sure this exactly fills your need because you would need to set the timeout to something where pings could actually be received.

Lastly there could simply be a boolean switch to have the Count parameter act like GNU ping and exit after sending the last ping.

from ping.

Lvzhenqian avatar Lvzhenqian commented on August 15, 2024

My requirement is to send a packet, wait for the duration of receiving a packet, increase the timeout count if failure and exit the program after waiting for receiving 10 packets, regardless of whether the 10 packets have timeouts or not.

I think the Boolean switch is a great option for exiting ping.

from ping.

sparrc avatar sparrc commented on August 15, 2024

wait for the duration of receiving a packet

Do you mean you want to wait for Interval seconds, or you want another configurable option for this duration?

from ping.

Lvzhenqian avatar Lvzhenqian commented on August 15, 2024

Yes, wait for interval seconds. When timeout should be interval+timeout to send again

from ping.

cyounkins avatar cyounkins commented on August 15, 2024

First, thank you for this project!

Without per-packet timeout, the problem I see is that when sending a set of probes, the earlier probes have more time to have responses. Say you send two probes, one at each t=0 and t=1 seconds. Then either deadline or control-C stops listening for replies at t=2. If the response time was a constant 1500ms, the first probe would receive a reply but the second would count as a loss. Max response time is equally problematic and tends to increase with larger count.

It's incorrect to interpret the packet loss results of any ping tool as "the client never responded" since the tools can't show that the remote won't reply, say, tomorrow. Of course a delay of hours is unlikely but when dealing with troubled, congested and highly buffered networks, tens of seconds is not unheard of.

Tools and libraries should permit a clear interpretation of packet loss. If you introduce a per-probe timeout, ignore replies past the timeout and wait the duration after sending the last probe, then packet loss can be interpreted as "probes that did not receive a reply within X time". All response times are then bounded.

Side note: What is called 'timeout' in this project is 'deadline' in UNIX ping, and I think the UNIX naming makes sense when both are used. 'Deadline' is when everything has to be done.

Is this something the developers would be interested in seeing added?

from ping.

stanimirivanovde avatar stanimirivanovde commented on August 15, 2024

Looks like I opened a dup: #209

from ping.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.