Code Monkey home page Code Monkey logo

krlivestream's Introduction

KRLiveStream

KRLiveStream connects seamlessly to your Redis Pub/Sub Server from your iOS or Mac app and patiently listens for messages sent to it. It manages the socket connection to Redis using CocoaAsyncSocket in the background, always listening for new messages sent to it without disconnecting (unless your app terminates, enters the background, times out on the server, or you specifically disconnect). All messages need to be sent in JSON and will be parsed using JSONKit as an NSDictionary.

We built KRLiveStream for Keyhole.IO as we use Redis as our Pub/Sub server. If you're looking for a cloud-based key-value pair store with live data streaming and messaging, look no further than Keyhole.IO!

Dependencies:

  1. JSONKit
  2. CocoaAsyncSocket
    (both are included in the KRLiveStream directory).

Getting Started

Just drag the KRLiveStream directory from Finder into your Xcode project and then include it in one of your headers.

Examples

Add the protocol to a controller
@interface RootViewController : UITableViewController <KRLiveStreamDelegate>

Connect and listen for messages
[[KRLiveStream sharedKRLiveStream] connectToServer:@"keyhole.io" port:[NSNumber numberWithInt:6379] channel:@"my_spiffy_channel" delegate:self];
You can also use this method to change from one channel to another. It'll automatically unsubscribe you from the previous channel before connecting to the new channel.

Listen for connection callback (optional)
- (void)liveStreamConnected { NSLog(@"Server connected"); }

Get a message and react (required)
- (void)liveStreamMessageReceived:(NSDictionary *)message { NSLog(@"Received message: %@", message); }

Disconnect from server
- (IBAction)disconnect { [[KRLiveStream] sharedKRLiveStream] disconnectFromServer]; }

Disconnection callback (optional)
- (void)liveStreamDisconnected { NSLog(@"Server disconnected"); }

To do

  1. Implement support for multiple connections. Current implementation only allows for a connection to one Redis Pub/Sub channel at a time.
  2. Tests (OMG, so bad, I know, but I will get around to doing this).

Feel free to fork, fix, add more features and submit a pull request!

Kishyr Ramdial
Keyhole.IO

krlivestream's People

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.