Comments (11)
Sorry I'm not sure I understand, can you explain what you are trying to accomplish?
from ping.
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.
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.
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.
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.
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.
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.
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.
Yes, wait for interval
seconds. When timeout should be interval
+timeout
to send again
from ping.
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.
Looks like I opened a dup: #209
from ping.
Related Issues (20)
- ping result is always same for different addresses HOT 2
- Event for detecting when a ping request times out HOT 1
- Pings not being returned after a certain number of IP addresses HOT 1
- Randomly running into issue while continously pinging 1.1.1.1 HOT 2
- logger.Fatal() causes entire app to exit HOT 5
- If the host is down ping blocks until the timeout is reached
- bind: cannot assign requested address HOT 2
- cannot find package HOT 2
- ping multiple hosts HOT 1
- 有时候莫名其妙的卡住 HOT 2
- In "mac", the call "pinger.Run()" struck for ever
- How to get network interface used to make the ping? HOT 3
- Some packet loss causes ping to hang forever HOT 3
- Is this project abandoned? HOT 3
- not support ipv6? HOT 1
- Decrease the number of digits after the decimal point HOT 1
- connection times out HOT 1
- What does it mean to ping over "udp"? HOT 1
- Mahsa1382
- Mahsa
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ping.