Code Monkey home page Code Monkey logo

ddtcpclient's Introduction

DDTCPClient

DDTCPClient is a high level socket util based on CocoaAsyncSocket.

Features

  • Thread safety, socket operations is on serial queue.
  • Subcontracting and Sticky bag.
  • Maintain read package one.
  • Network state monitoring and reconnection mechanism.
  • Heartbeat mechanism.

Installation

CocoaPods

  1. Add pod 'DDTCPClient' to your Podfile.
  2. Run pod install or pod update.
  3. Import <DDTCPClient/DDTCPClient.h>.

Manually

  1. Download all the files in the Source subdirectory.
  2. Add the source files to your Xcode project.
  3. Import DDTCPClient.h.

Usage

Initialization

DDTCPClient *socket = [[DDTCPClient alloc] init];
socket.delegate = self;

Property

// debug log open
socket.isDebug = YES;
// default is 10, set -1 when reconnect forever
socket.reconnectCount = -1;
// reconnect timeInterval
socket.reconnectTimeInterval = 5;

Connect and disconnect

// Connect
[socket connectHost:host port:port];
    
// Disconnect
[socket disConnect];

Sent heart or send data

// Send data
NSString *registStr = @"I'm register informations";
NSData *registData = [registStr dataUsingEncoding:NSUTF8StringEncoding];
    
[socket sendData:registData];

// Sent heart, just set once, heart data will be send one by one
NSString *heartStr = @"I'm heart informations";
NSData *heartData = [heartStr dataUsingEncoding:NSUTF8StringEncoding];
    
[socket setHeartData:heartData];

Delegate

- (void)client:(DDTCPClient *)client didReadData:(NSData *)data {
    NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"DDAsyncSocket -- %@", str);
}
- (void)client:(DDTCPClient *)client didConnect:(NSString *)host port:(uint16_t)port {

}
- (void)clientDidDisconnect:(DDTCPClient *)client {

}

Requirements

This library requires iOS 8.0+.

License

DDTCPClient is provided under the MIT license. See LICENSE file for details.

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.