-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
121 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,75 @@ | ||
![Swift CI](https://github.com/Local-Connectivity-Lab/lcl-ping/actions/workflows/build.yaml/badge.svg?branch=main) | ||
<p align:center> | ||
<img src="images/logo.png" alt="Logo" width="557> | ||
</p> | ||
|
||
|
||
# LCLPing | ||
|
||
![Swift CI](https://github.com/Local-Connectivity-Lab/lcl-ping/actions/workflows/build.yaml/badge.svg?branch=main) | ||
|
||
LCLPing is a cross-platform Ping library written in Swift, and for Swift. It is designed to help streamline testing, measuring, and monitoring network reachability of a host for both the client side and server side applications and services. | ||
|
||
|
||
## Requirements | ||
- Swift 5.7+ | ||
- Swift 5.9+ | ||
- macOS 10.15+, iOS 14+, Linux | ||
|
||
## Getting Started | ||
|
||
## Installation | ||
|
||
### Swift Package Manager (SPM) | ||
|
||
Add the following to your `Package.swift` file: | ||
```code | ||
.package(url: "https://github.com/Local-Connectivity-Lab/lcl-ping.git", from: "0.2.0") | ||
``` | ||
|
||
Then import the module to your project | ||
```code | ||
.target( | ||
name: "YourAppName", | ||
.dependencies: [ | ||
.product(name: "LCLPing", package: "lcl-ping") | ||
] | ||
) | ||
``` | ||
|
||
### Basic Usage | ||
|
||
```swift | ||
// create ping configuration for each run | ||
let pingConfig = LCLPing.PingConfiguration(type: pingType, endpoint: endpoint) | ||
|
||
// create ping options | ||
#if os(macOS) || os(iOS) | ||
let options = LCLPing.Options(verbose: verbose, useNative: useURLSession) | ||
#else | ||
let options = LCLPing.Options(verbose: verbose) | ||
#endif | ||
|
||
// initialize ping object with the options | ||
var ping = LCLPing(options: options) | ||
|
||
try await ping.start(pingConfiguration: pingConfig) | ||
switch ping.status { | ||
case .error, .ready, .running: | ||
// handle error here | ||
case .stopped, .finished: | ||
// retrieve ping summary | ||
print(ping.summary) | ||
} | ||
``` | ||
|
||
You can also run the [demo](/Sources/Demo/README.md) using `make demo` or `swift run Demo` if you do not have make installed. | ||
|
||
### Features | ||
- Ping via ICMP and HTTP(S) | ||
- Support IPv4 | ||
- flexible and configurable wait time, time-to-live, count, and duration | ||
|
||
|
||
## Contributing | ||
Any contribution and pull requests are welcome! However, before you plan to implement some features or try to fix an uncertain issue, it is recommended to open a discussion first. You can also join our [Discord channel](https://discord.com/invite/gn4DKF83bP), or visit our [website](https://seattlecommunitynetwork.org/). | ||
|
||
## License | ||
LCLPing is released under Apache License. See [LICENSE](/LICENSE) for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# LCLPing Demo | ||
|
||
This example provides a simple look at how LCLPing can be used to issue ICMP requests and wait for corresponding responses | ||
|
||
```bash | ||
make demo | ||
# OR | ||
swift run Demo | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// This source file is part of the LCL open source project | ||
// | ||
// Copyright (c) 2021-2023 Local Connectivity Lab and the project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE for license information | ||
// See CONTRIBUTORS for the list of project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#if swift(>=5.9) | ||
import Foundation | ||
import LCLPing | ||
|
||
// create ping configuration for each run | ||
let pingConfig = LCLPing.PingConfiguration(type: .icmp, endpoint: .ipv4("google.com", 0)) | ||
|
||
// create ping options | ||
#if os(macOS) || os(iOS) | ||
let options = LCLPing.Options(verbose: false, useNative: false) | ||
#else | ||
let options = LCLPing.Options(verbose: false) | ||
#endif | ||
|
||
// initialize ping object with the options | ||
var ping = LCLPing(options: options) | ||
|
||
try await ping.start(pingConfiguration: pingConfig) | ||
switch ping.status { | ||
case .error, .ready, .running: | ||
print("LCLPing is in invalid state. Abort") | ||
case .stopped, .finished: | ||
print(ping.summary) | ||
} | ||
#else | ||
fatalError("Requires at least Swift 5.9") | ||
#endif |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.