Skip to content

Commit

Permalink
Init - JAPing
Browse files Browse the repository at this point in the history
  • Loading branch information
JadianZheng committed Sep 3, 2018
1 parent 992f6a9 commit a6d3430
Show file tree
Hide file tree
Showing 42 changed files with 3,337 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Example/JAPing.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
62E4816DA6AFD3258DCCB7A0 /* Pods-JAPing_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JAPing_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-JAPing_Example/Pods-JAPing_Example.release.xcconfig"; sourceTree = "<group>"; };
73B84944CDBD28A4545C8352 /* Pods-JAPing_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JAPing_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-JAPing_Tests/Pods-JAPing_Tests.debug.xcconfig"; sourceTree = "<group>"; };
931ED652ED1458467801FF2D /* Pods-JAPing_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JAPing_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-JAPing_Tests/Pods-JAPing_Tests.release.xcconfig"; sourceTree = "<group>"; };
AF9D27D2159F6D452D15F72B /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; name = README.md; path = ../README.md; sourceTree = "<group>"; };
DF12BF9555D903B7429187FC /* JAPing.podspec */ = {isa = PBXFileReference; includeInIndex = 1; name = JAPing.podspec; path = ../JAPing.podspec; sourceTree = "<group>"; };
F7670AC59374A6ECD1CD190D /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
AF9D27D2159F6D452D15F72B /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
DF12BF9555D903B7429187FC /* JAPing.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = JAPing.podspec; path = ../JAPing.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
F7670AC59374A6ECD1CD190D /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down
10 changes: 10 additions & 0 deletions Example/JAPing.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
58 changes: 51 additions & 7 deletions Example/JAPing/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,62 @@
//

import UIKit
import JAPing

class ViewController: UIViewController {
extension Double {
func roundUp(to decimal: Int) -> Double {
let multiple: Double = pow(10.0, Double(decimal))
return Darwin.round(self * multiple)/multiple
}
}

class ViewController: UIViewController {
let baiduPinger = JAPing(hostName: "baidu.com", unexpertError: nil)
let hostSelector = JAHostSelector(hosts: ["baidu.com", "jd.com"]);

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

pingBaidu()
// mutiplePing()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.

func mutiplePing() {
hostSelector.startPing(10) { [unowned self] (fastestHost, sortedPingResults) in
print("Fastest: \(fastestHost)")
print(sortedPingResults)
// self.mutiplePing()
}
}

func pingBaidu() {
baiduPinger.resolvedHostHandle = { pinger, ip in
print("PING \(pinger.hostName) (\(ip))")
}

baiduPinger.packetResponseHandle = { pinger, sequenceNumber, packet in
print("\(packet.sendData.count) bytes from \(pinger.ip): icmp_seq=\(sequenceNumber) time=\(packet.roundTripTime.roundUp(to: 3)) ms")
}

baiduPinger.pingFinishHandle = { pinger, packets, statistic in
if statistic.ip.isEmpty {
print("JAPing: cannot resolve \(pinger.hostName): Unknown host")
return
}

print("--- \(pinger.hostName) ping statistics ---")

let lossPercent = (statistic.transmittedPacketCount - statistic.receivedPacketCount)/statistic.transmittedPacketCount * 100
print("\(statistic.transmittedPacketCount) packets transmitted, \(statistic.receivedPacketCount) packets received, \(lossPercent)% packet loss")

if statistic.receivedPacketCount > 0 {
print("round-trip min/avg/max/stddev = \(statistic.minRoundTripTime.roundUp(to: 3))/\(statistic.avgRoundTripTime.roundUp(to: 3))/\(statistic.maxRoundTripTime.roundUp(to: 3))/\(statistic.stddevRoundTripTime.roundUp(to: 3)) ms")
// pinger.start()
}
}

baiduPinger.configuare.pingCount = 8
baiduPinger.start()
}

}

16 changes: 16 additions & 0 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PODS:
- JAPing (0.1.0)

DEPENDENCIES:
- JAPing (from `../`)

EXTERNAL SOURCES:
JAPing:
:path: "../"

SPEC CHECKSUMS:
JAPing: 69f8dda2665ea110b85e668a5ff657cc26fa8311

PODFILE CHECKSUM: 4fd24534942f398f84b59a8f32bdba6f6cb01c5e

COCOAPODS: 1.5.3
22 changes: 22 additions & 0 deletions Example/Pods/Local Podspecs/JAPing.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a6d3430

Please sign in to comment.