Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pings to same servers are much higher on Mac than iOS #34

Open
houmie opened this issue Aug 14, 2021 · 3 comments
Open

Pings to same servers are much higher on Mac than iOS #34

houmie opened this issue Aug 14, 2021 · 3 comments

Comments

@houmie
Copy link

houmie commented Aug 14, 2021

A very strange behaviour. I get 60ms ping on iOS and same server on Mac shows 230ms.
Is there a good way to do 5 pings and get the average of it?

@samiyr
Copy link
Owner

samiyr commented Aug 16, 2021

If you ping the same host on your Mac with the command line utility ping, do you still get the same ping time of ~230ms?

As for getting the average, there's a PingResult which contains some statistical data, including the average. Here's a rough (untested, errors not handled etc) idea of how to ping 5 times and get the average:

let ping = try! SwiftyPing(host: "google.com", configuration: PingConfiguration(interval: 1.0, with: 1), queue: DispatchQueue.global())
// this is called after every ping
ping.observer = { (response) in
    print("\(response.duration * 1000) ms"
}
// this is called after five pings
ping.finished = { (result) in
    print("avg roundtrip: \(result.roundtrip!.average * 1000) ms")
}
ping.targetCount = 5
try! ping.startPinging()

@houmie
Copy link
Author

houmie commented Feb 26, 2022

Sorry @samiyr for the late response.

I have applied your suggestion. Unfortunately the issue remains. I live in London and the server ping to a server in London should be very low.

On Mac if my count is set as one, I get 206 ms. This is clearly wrong.
count two gets to a more believable average of 96ms.
count three gets to 64 ms.

SwiftyPing on iOS with count one return 4ms ping to the same server. How comes that SwiftyPing shows much lower ping when used on iOS than when SwiftyPing is used on Mac? The Mac version is somehow bugged.

I think this is a very useful project. It would be great to make it more consistent across the platforms though. I'm not sure why this is happening.

func pingServer(_ serverIP: String, _ count: Int, completed: @escaping serverPingCompletedClosure) {
        let ping = try? SwiftyPing(host: serverIP, configuration: PingConfiguration(interval: 1.0, with: 1), queue: DispatchQueue.global())
        ping?.finished = { (result) in
            completed(result.roundtrip!.average)
        }
        ping?.targetCount = count
        try? ping?.startPinging()
    }

Many Thanks.

@ghost
Copy link

ghost commented Apr 26, 2023

Had the same problem, and finally figured it out on Mac! You have to enable both capabilities "Incoming Connections (Server)" and "Outcoming Connections (Client)" in App Sandbox, then it works! Now latency is exactly the same like on iOS and Terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants