GithubHelp home page GithubHelp logo

gy37 / websocketstompkit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rguldener/websocketstompkit

0.0 0.0 0.0 133 KB

STOMP over websocket client for iOS

License: Apache License 2.0

Ruby 2.17% Objective-C 97.83%

websocketstompkit's Introduction

WebsocketStompKit

Maintainer wanted
As I currently don't use WebsocketStompKit in any of my active apps the time I can spend on it is very limited. Many of you have provided improvements and fixes through issues and pull requests. If somebody wants to take over and get commit access please contact me at [email protected]

Current version: 0.1.1 (version mirrored to StompKit)

WebsocketStompKit is STOMP over websocket for iOS. It is built on the great StompKit and replaces its socket handling library with the very well done Jetfire websocket library.

Why would I want to run STOMP over websockets on iOS?

Probably you already have a server that speaks STOMP over websockets. If you don't expect to have tens of thousands of clients at the same time, why rewrite everything from scratch? With WebsocketStompKit one server can handle both iOS and web clients.

Installation

Install with Cocoapods

...
pod 'WebsocketStompKit', :git => 'https://github.com/rguldener/WebsocketStompKit.git', :tag => '0.1.1'
...

Jetfire comes as a dependency so be prepared for that.

Usage

Import into your project/Objective-C headers bridge file (for Swift)

#import <WebsocketStompKit/WebsocketStompKit.h>

Then instantiate the STOMPClient class

NSURL *websocketUrl = [NSURL urlWithString:@"ws://my-great-server.com/websocket"];
STOMPClient *client = [[STOMPClient alloc] initWithURL:websocketUrl websocketHeaders:nil useHeartbeat:NO];

websocketHeaders accepts an NSDictionary of additional HTTP header entries that should be passed along with the initial websocket request. This is especially useful if you need to authenticate with cookies as by default Jetfire will not pass cookies along with your initial websocket-upgrade HTTP request.
useHeartbeat allows you to deactivate the heartbeat component of STOMP (which is optional) as it is not supported by all STOMP brokers.

Once you have your client object you can connect in the same way as with StompKit

// connect to the broker
[client connectWithLogin:@"mylogin"
                passcode:@"mypassword"
       completionHandler:^(STOMPFrame *_, NSError *error) {
            if (err) {
                NSLog(@"%@", error);
                return;
            }

            // send a message
            [client sendTo:@"/queue/myqueue" body:@"Hello, iOS!"];
            // and disconnect
            [client disconnect];
        }];

Note that the completion handler which you pass into the connect method will also be called when the websocket connection gets closed or if the connection creation does not succeed.

The rest of the provided methods are the same as in StompKit, please refer to its Readme for basic usage information

Differences to StompKit

Easy:

  • Routes STOMP messages over websocket connection instead of a raw TCP socket
  • Allows deactivation of heartbeat functionality

I plan to keep this in sync with StompKit moving forward and will mirror their versioning here.

Authors

websocketstompkit's People

Contributors

gy37 avatar jmesnil avatar matzew avatar rguldener 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.