Git Product home page Git Product logo

fayeclient's Introduction

FayeClient - iOS & Mac OS X

This project is an updated version of the Library made by pcrawfor there: https://github.com/pcrawfor/FayeObjC

Why?

For one of my project, I needed an objective-C faye client. The best I've been able to find is the one created by pcrawfor which is not maintained anymore. I decided to copy the project and update the web socket library in order to user Socket Rockect, maintainted by Square, JSONKit, and make the library using ARC by default.

Installation


  1. Setup Cocoapods for your project http://cocoapods.org/
  2. Download the last version of FayeClient
  3. The downloaded folder contains an Example folder which is an example of use of the FayeClient, and the Library folder with the sources of the library. Copy the Library folder on your project.
  4. Compile your project, your should be ready to go!

Usage


Connection and messages

  • Install the library
  • Import the library in the file where you need it:
#import #import "FayeClient.h"
  • Create a property for the FayeClient object
@property (nonatomic, strong) FayeClient *client;
  • Initialize the client with the URL of the server and the channel you want to be subscribed to:
_client = [[FayeClient alloc] initWithURLString:@"ws://localhost:9292/hub" channel:@"/room1"];
  • Open the connection with the server:
[_client connectToServer]
  • Send a message:
[_client sendMessage:@{@"jayztemplier" : @"Hello World!"}];

Delegate

You can also add a delegate to the Faye Client in order to have some feebacks about what happened:

  @protocol SRWebSocketDelegate <NSObject>

  - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;

  @optional

  - (void)webSocketDidOpen:(SRWebSocket *)webSocket;
  - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
  - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;

  @end

Faye Server

If you can to run a Faye server to test the client, you can find all the information you need there: http://faye.jcoglan.com/ You can also run the server.rb file under the Server directory:

gem install faye
ruby ./server.rb

##Dependencies

SocketRocket

A conforming WebSocket (RFC 6455) client library maintained by Square, https://github.com/square/SocketRocket

JSONKit

Powerful JSON Parser https://github.com/johnezang/JSONKit

fayeclient's People

Contributors

jayztemplier avatar

Watchers

James Cloos 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.