Giter VIP home page Giter VIP logo

djpingaction's Introduction

DJPingAction

检测网络的连通性,一般会用ping操作.即向主机发送一个ICMP的包.苹果的SimplePing代码中帮我们实现了一个简单的ping操作.即封装了底层往主机发ICMP包的过程.但是这个ping操作还是过于简陋,它只管了如何发ICMP包.对一些典型的业务场景,比如检测网络连通性,使用起来还是相对复杂.

DJPingAction就是在苹果的SimplePing基础上进行了封装.

  • 封装了SimplePing的各种代理.一般情况下,我们对Ping的发包过程并不关心,只关心包的到达结果.因此对外只提供包到达结果即可.

  • 封装了超时的机制.SimplePing只是管了发ICMP包,并没有对超时没有收到包的情况做处理.

  • 封装了对象管理. 调用DJPingAction startWithHost:timeOutLimit:stopWhenReached:maxCount:feedback:complete之后,内部会维护一个DJPingAction对象,在complete的block回来之后,这个对象一直存在.不需要再调用的地方维护DJPingAction 对象.

  • 让ping的动作在单独的线程中执行.

安装

pod 'DJPingAction'

使用

#import "DJPingAction.h"

// host: 主机名
// timeOutLimit: ICMP包发出去之后,多久没收到即认为超时.单位 秒.
// stopWhenReached: 是否已经收到一个成功包之后,后面的包就不用再发了.一般用于典型的网络连通性检测中.
// maxCount: 最大包的个数
// feedback: 每个包的发送结果回调
// complete: ping动作完成之后的回调. 执行这个回调之后,释放所有内部对象.

[DJPingAction startWithHost:@"qq.com"
                   timeOutLimit:1.0f
                stopWhenReached:NO
                       maxCount:3
                       feedback:^(DJPingItem *item) {
    NSLog(@"ping Action item = %@",item);
} complete:^{
    NSLog(@"ping Action finished!");
}];

djpingaction's People

Contributors

qiushuitian avatar wang68543 avatar

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.