项目作者: sizeofanton

项目描述 :
RxJava ping wrapper for Android
高级语言: Kotlin
项目地址: git://github.com/sizeofanton/RoboPing.git
创建时间: 2020-10-04T20:51:51Z
项目社区:https://github.com/sizeofanton/RoboPing

开源协议:GNU General Public License v3.0

下载


RoboPing

License: GPL API

A small library wrapper for calling /system/bin/ping and get the result as RxJava’s Completable or Observable<String> classes

Installation:

Add this to your project level build.gradle file:

  1. repositories {
  2. maven { url "https://jitpack.io" }
  3. }

And then add this to your module level build.gradle:

  1. dependencies {
  2. implementation 'com.github.sizeofanton:RoboPing:1.0'
  3. }

Usage:

Building an instance:

  1. val pingWrapper = RoboPing.Builder()
  2. .setCount(10)
  3. .setInterval(2)
  4. .build()

All available Builder methods:

Method Description
enableBroadcast() Allows pinging a broadcast address
setCount(count: Int) Set the number of times to send the ping request
enableSoDebug() Set the SO-DEBUG option on the socket being used
enableFlood() Flood the network by sending hundred or more packets per second
setInterval(interval: Int) Specify an interval between successive packet transmissions
setTtl(ttl: Int) Set the Time To Live (number of hops)
setDeadline(deadline: Int) Specify a timeout, in seconds, before ping exits
setTimeout(timeout: Int) Set the time(seconds) to wait for a response
build() Creates RoboPing class instance with specified parameters

RoboPing contains two methods, one that returns a Completable class without any additional information and the one that returns an Observable<String> with a ping command’s stdout and stderr , that will be transmited to observers.

Silent ping example:

  1. val pingWrapper = RoboPing.Builder().build()
  2. pingWrapper.ping(host)
  3. .subscribeOn(Schedulers.io())
  4. .observeOn(AndroidSchedulers.mainThread())
  5. .subscribe({
  6. Toast.makeText(this, "Host reachable", Toast.LENGTH_LONG).show()
  7. },{
  8. Toast.makeText(this, "Host unreachable", Toast.LENGTH_LONG).show()
  9. })

Verbose ping example:

  1. val pingWrapper = RoboPing.Builder().build()
  2. pingWrapper.ping(host)
  3. .subscribeOn(Schedulers.io())
  4. .observeOn(AndroidSchedulers.mainThread())
  5. .subscribe({
  6. log.append(it)
  7. },{
  8. log.append(errorMsg)
  9. })