ios 開發 ping


在win 或 mac系統的終端下都有方便的ping命令來檢測網絡的連通性!

在iOS上可以使用蘋果封裝好的工具來開發ping連接測試

SimplePing 下載

1. 主要接口

//初始化一個地址
- (instancetype)initWithHostName:(NSString *)hostName NS_DESIGNATED_INITIALIZER;

//開始ping
- (void)start;

//發送ping數據
- (void)sendPingWithData:(nullable NSData *)data;

//停止
- (void)stop;

2. 主要回調

@optional


//ping 開始
- (void)simplePing:(SimplePing *)pinger didStartWithAddress:(NSData *)address;


//ping 失敗
- (void)simplePing:(SimplePing *)pinger didFailWithError:(NSError *)error;

//成功發送一份ping數據
- (void)simplePing:(SimplePing *)pinger didSendPacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber;

//發送ping數據失敗
- (void)simplePing:(SimplePing *)pinger didFailToSendPacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber error:(NSError *)error;


//收到ping響應數據
- (void)simplePing:(SimplePing *)pinger didReceivePingResponsePacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber;


//收到未知響應數據
- (void)simplePing:(SimplePing *)pinger didReceiveUnexpectedPacket:(NSData *)packet;

3. 測試程序SimplePing app

    

4. 示例中還有一個測試用的mactool,編譯生成可執行文件,在終端下執行 

 ./SimplePing -4 www.baidu.com

  這樣即可測試

 

https://developer.apple.com/library/content/samplecode/SimplePing/Introduction/Intro.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM