Giter VIP home page Giter VIP logo

kt_ping's Introduction

Ping for Android in Kotlin

CircleCI Codacy Badge

Description

This is a demonstration of an ICMP ping application for Android with configurable size and interval. The application executes a system ping process with defined paramteres and uses a simple regex to parse values. Some very basic exceptions handling is implemented.

The figure below shows a screenshot of a simulated run.

Implementation details

The main application logic is located in MainActivity.kt.

Class class PingProcess : Runnable contains a ping thread, it reads parameters from the inputs and forms a string array cmd

val serverAddr = textServer.text.toString()
val size = textSize.text.toString()
val interval = textInterval.text.toString()

val cmd = mutableListOf("ping", "-D")
if (size != "") {
    cmd.addAll(arrayOf("-s", size))
}
if (interval != "") {
    cmd.addAll(arrayOf("-i", interval))
}
cmd.add(serverAddr)

Then, we create a process and initialize buffer reader

val process = Runtime.getRuntime().exec(cmd.toTypedArray())
val stdInput = BufferedReader(InputStreamReader(process.inputStream))

Considering that ping runs indefinetely, we are continiously reading process output until we stop it and send it to the main thread to update the UI

for (l in stdInput.lines()) {
    if (!isThreadRunning) {
        break
    }
    lastPingString = l

    val messagePing = Message()
    messagePing.what = PING
    mHandlerThread.sendMessage(messagePing)
}

Authorship and license

Igor Kim

The repository is distributed under MIT license.

kt_ping's People

Contributors

igorskh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

junijen

kt_ping's Issues

java.lang.NullPointerException

java.lang.NullPointerException: process.errorStream.bufferedReader().readLine() must not be null

just from example app

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.