Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
WebSocket client for Cocoa
Objective-C C Ruby JavaScript
Tree: 77f0882b11

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
PKWebSocket.xcodeproj
PKWebSocket
PKWebSocketTests
Submodules
.gitignore
.gitmodules
README.md

README.md

PKWebSocket / WebSocket client for Cocoa

TODO

  • Propper socket status handling
  • Implement propper framing for the protocols
  • Implement RFC6455 (Handshake works framing doesn't)
  • Error reporting sucks
  • Documentation
  • Implement closing handshakes
  • Test with Socket.IO & Node.js

Compatiblity

Protocols

  • Hixie 75 (Text frames only)
  • Hixie 76 (Text frames only)
  • RFC6455 (WIP)

Servers (tested)

  • em-websocket
  • ws://echo.websocket.org

Usage

#import "PKWebSocket.h"
#import "PKWebSocketHandler-Hixie76.h"

NSURL *url = @"ws://echo.websocket.org";
PKWebSocketHandlerHixie76 *handler = [[PKWebSocketHandlerHixie76 alloc] init];
PKWebSocket *ws = [[PKWebSocket alloc] initWithURLString:url
                                                 handler:handler
                                                delegate:self];
NSError *error;
if ([ws openWithError:&error]) {
  [ws send:@"string to send"];
  [ws close];
}

Delegate methods

On the delegate WebSocket call following methods if you opt for them:

- (void)webSocket:(PKWebSocket *)webSocket didFailWithError:(NSError *)error;
- (void)webSocketDidOpen:(PKWebSocket *)webSocket;
- (void)webSocketDidClose:(PKWebSocket *)webSocket;
- (void)webSocket:(PKWebSocket *)webSocket didReceiveMessage:(NSString *)message;
- (void)webSocketDidSendMessage:(PKWebSocket *)webSocket;
- (void)webSocketDidSecure:(PKWebSocket *)webSocket;

Using secure WebSocket

NSURL *url = [NSURL URLWithString:@"wss://echo.websocket.org"];
NSMutableDictionary *tlsSettings = [NSMutableDictionary dictionaryWithCapacity:4];
[tlsSettings setObject:url.host forKey:(NSString *)kCFStreamSSLPeerName];

// Allow expired certificates
[tlsSettings setObject:[NSNumber numberWithBool:YES]
                forKey:(NSString *)kCFStreamSSLAllowsExpiredCertificates];

// Allow self-signed certificates
[tlsSettings setObject:[NSNumber numberWithBool:YES]
                forKey:(NSString *)kCFStreamSSLAllowsAnyRoot];

// In fact, don't even validate the certificate chain
[tlsSettings setObject:[NSNumber numberWithBool:NO]
                forKey:(NSString *)kCFStreamSSLValidatesCertificateChain];

NSError *error;
PKWebSocket *ws = [[PKWebSocket alloc] initWithURLString:[url absoluteString]
                                     handler:_handler
                                    delegate:self];
ws.tlsSettings = tlsSettings;
if ([ws openWithError:&error]) {
...
}

Requirements & Dependencies & Submodules

Get code & Contribute

TOWRITE

Code

If you have GIT 1.7+ ...

git clone git@github.com:pk/PKWebSocket.git --recursive

or, earlier...

git clone git@github.com:pk/PKWebSocket.git
cd PKWebSocket
git submodule init
git submodule update

Test suite

TOWRITE

Adding to your project

TOWRITE

Based on

Something went wrong with that request. Please try again.