Permalink
Browse files

Updated documentation.

  • Loading branch information...
1 parent 0aa9b85 commit a784f61b49448273b7c4128aad55c035cea5d6ff @pk committed Apr 19, 2012
Showing with 39 additions and 5 deletions.
  1. +39 −5 README.md
View
@@ -11,12 +11,18 @@
#import "PKWebSocket.h"
#import "PKWebSocketHandler-Hixie76.h"
- NSURL *url = [NSURL URLWithString:@"ws://example.com"];
+ NSURL *url = @"ws://echo.websocket.org";
PKWebSocketHandlerHixie76 *handler = [[PKWebSocketHandlerHixie76 alloc] init];
- PKWebSocket *ws = [[PKWebSocket alloc] initWithURLString:url handler:handler delegate:self];
- [ws open];
- [ws send:@"string to send"];
- [ws close];
+ 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:
@@ -27,6 +33,34 @@ On the delegate WebSocket call following methods if you opt for them:
- (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

0 comments on commit a784f61

Please sign in to comment.