Code Monkey home page Code Monkey logo

siosocket's Introduction

SIOSocket

SIOSocket is simple interface for communicating with Socket.IO 1.0 from iOS. There is now a first-party iOS client for Socket.IO! Congrats to the Socket.IO team for a job well done.

How to use

SIOSocket can be added as a CocodaPod, submodule, or standalone dependency to any iOS 7.0 (or greater) project.

pod 'SIOSocket', '~> 0.2.0'

then...

#import <SIOSocket/SIOSocket.h>

// ...
[SIOSocket socketWithHost: @"http://localhost:3000" response: ^(SIOSocket *socket) {
    self.socket = socket;
}];

or, in Swift...

// ...
SIOSocket.socketWithHost("http://localhost:3000") { (socket: SIOSocket) in
    self.socket = socket
}

A full demo can be found over at MegaBits/WorldPin

Types

typedef NSArray SIOParameterArray

An NSArray of these JSValue-valid objects:

  • NSNull
  • NSString
  • NSNumber
  • NSDictionary
  • NSArray
  • NSData

Generators

+ (void)socketWithHost:response:

Generates a new SIOSocket object, begins its connection to the given host, and returns it as the sole parameter of the response block.

The host reachable at the given URL string should be running a valid instance of a socket.io server.

+ (void)socketWithHost:reconnectAutomatically:attemptLimit:withDelay:maximumDelay:timeout:withTransports:response:

  • reconnectAutomatically whether to reconnect automatically (YES)
  • attemptLimit number of times to attempt a reconnect (Infinite)
  • reconnectionDelay how long to wait before attempting a new reconnection (1)
  • maximumDelay maximum amount of time to wait between reconnections (5). Each attempt increases the reconnection by the amount specified by reconnectionDelay.
  • timeout connection timeout before an onReconnectionError event is emitted (20)
  • withTransports specifies an array of transports for engine.io (default is 'polling', 'websocket').

Properties

void (^onConnect)()

Called upon connecting.

void (^onDisconnect)()

Called upon a disconnection.

void (^onError)(NSDictionary *errorInfo)

Called upon a connection error.

void (^onReconnect)(NSInteger numberOfAttempts)

Called upon a successful reconnection.

void (^onReconnectionAttempt)(NSInteger numberOfAttempts)

Called upon an attempt to reconnect.

void (^onReconnectionError)(NSDictionary *errorInfo)

Called upon a reconnection attempt error.

Responders

-(void)on:callback:

Binds the given void (^)(SIOParameterArray *) block, function, to the given event.

function is called upon a firing of event.

Emitters

-(void)emit:args:

Fires the given event with then given SIOParameterArray as arguments.

License

MIT

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.