GithubHelp home page GithubHelp logo

opportunitylivetv / socketrocket Goto Github PK

View Code? Open in Web Editor NEW

This project forked from facebookincubator/socketrocket

1.0 3.0 1.0 2.47 MB

A conforming Objective-C WebSocket client library.

License: Other

Ruby 0.59% Makefile 0.40% Objective-C 94.17% Go 0.84% Python 1.25% HTML 0.42% JavaScript 1.52% Shell 0.81%

socketrocket's Introduction

SocketRocket

Platforms License

Podspec Carthage Compatible

Build Status

A conforming WebSocket (RFC 6455) client library for iOS, macOS and tvOS.

Test results for SocketRocket here. You can compare to what modern browsers look like here.

SocketRocket currently conforms to all core ~300 of Autobahn's fuzzing tests (aside from two UTF-8 ones where it is merely non-strict tests 6.4.2 and 6.4.4).

Features/Design

  • TLS (wss) support, including self-signed certificates.
  • Seems to perform quite well.
  • Supports HTTP Proxies.
  • Supports IPv4/IPv6.
  • Supports SSL certificate pinning.
  • Sends ping and can process pong events.
  • Asynchronous and non-blocking. Most of the work is done on a background thread.
  • Supports iOS, macOS, tvOS.

Installing

There are a few options. Choose one, or just figure it out:

Add the following line to your Podfile:

pod 'SocketRocket'

Run pod install, and you are all set.

Add the following line to your Cartfile:

github "facebook/SocketRocket"

Run carthage update, and you should now have the latest version of SocketRocket in your Carthage folder.

  • Using SocketRocket as a sub-project

    You can also include SocketRocket as a subproject inside of your application if you'd prefer, although we do not recommend this, as it will increase your indexing time significantly. To do so, just drag and drop the SocketRocket.xcodeproj file into your workspace.

API

SRWebSocket

The Web Socket.

Note:

SRWebSocket will retain itself between -(void)open and when it closes, errors, or fails. This is similar to how NSURLConnection behaves (unlike NSURLConnection, SRWebSocket won't retain the delegate).

Interface

@interface SRWebSocket : NSObject

// Make it with this
- (instancetype)initWithURLRequest:(NSURLRequest *)request;

// Set this before opening
@property (nonatomic, weak) id <SRWebSocketDelegate> delegate;

// Open with this
- (void)open;

// Close it with this
- (void)close;

// Send a Data
- (void)sendData:(nullable NSData *)data error:(NSError **)error;

// Send a UTF8 String
- (void)sendString:(NSString *)string error:(NSError **)error;

@end

SRWebSocketDelegate

You implement this

@protocol SRWebSocketDelegate <NSObject>

@optional

- (void)webSocketDidOpen:(SRWebSocket *)webSocket;

- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithString:(NSString *)string;
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithData:(NSData *)data;

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

@end

Testing

Included are setup scripts for the python testing environment. It comes packaged with vitualenv so all the dependencies are installed in userland.

To run the short test from the command line, run:

  make test

To run all the tests, run:

  make test_all

The short tests don't include the performance tests (the test harness is actually the bottleneck, not SocketRocket).

The first time this is run, it may take a while to install the dependencies. It will be smooth sailing after that.

You can also run tests inside Xcode, which runs the same thing, but makes it easier to debug.

  • Choose the SocketRocket target
  • Run the test action (⌘+U)

TestChat Demo Application

SocketRocket includes a demo app, TestChat. It will "chat" with a listening websocket on port 9900.

TestChat Server

The sever takes a message and broadcasts it to all other connected clients.

It requires some dependencies though to run. We also want to reuse the virtualenv we made when we ran the tests. If you haven't run the tests yet, go into the SocketRocket root directory and type:

make test

This will set up your virtualenv.

Now, in your terminal:

source .env/bin/activate
pip install git+https://github.com/tornadoweb/tornado.git

In the same terminal session, start the chatroom server:

python TestChatServer/py/chatroom.py

There's also a Go implementation (with the latest weekly) where you can:

cd TestChatServer/go
go run chatroom.go

Chatting

Now, start TestChat.app (just run the target in the Xcode project). If you had it started already you can hit the refresh button to reconnect. It should say "Connected!" on top.

To talk with the app, open up your browser to http://localhost:9000 and start chatting.

WebSocket Server Implementation Recommendations

SocketRocket has been used with the following libraries:

The Tornado one is dirt simple and works like a charm. (IPython notebook uses it too). It's much easier to configure handlers and routes than in Autobahn/twisted.

Contributing

We’re glad you’re interested in SocketRocket, and we’d love to see where you take it. Please read our contributing guidelines prior to submitting a Pull Request.

socketrocket's People

Contributors

mikelikespie avatar nlutsenko avatar dfed avatar jleandroperez avatar natan avatar hamchapman avatar jakobsa avatar mk avatar dnkoutso avatar jmkk avatar kyleve avatar readmecritic avatar jakewharton avatar alanf avatar lukeredpath avatar fjolnir avatar richardjrossiii avatar michaelkirk avatar kwigginton avatar j0sh avatar pizthewiz avatar james-howard avatar erikprice avatar anulman avatar joenoon avatar m4rr avatar martinmroz avatar msch avatar charlesmchen avatar michaelpetrov avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

martina6hall

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.