forked from talkative/cocoa-websocket
-
Notifications
You must be signed in to change notification settings - Fork 1
/
WebSocket.h
70 lines (58 loc) · 1.98 KB
/
WebSocket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// WebSocket.h
//
// Originally created for Zimt by Esad Hajdarevic on 2/14/10.
// Copyright 2010 OpenResearch Software Development OG. All rights reserved.
//
// Erich Ocean made the code more generic.
//
// Tobias Rodäbel implemented support for draft-hixie-thewebsocketprotocol-76.
//
#import <Foundation/Foundation.h>
@class AsyncSocket;
@class WebSocket;
@protocol WebSocketDelegate<NSObject>
@optional
- (void)webSocket:(WebSocket*)webSocket didFailWithError:(NSError*)error;
- (void)webSocketDidOpen:(WebSocket*)webSocket;
- (void)webSocketDidClose:(WebSocket*)webSocket;
- (void)webSocket:(WebSocket*)webSocket didReceiveMessage:(NSString*)message;
- (void)webSocketDidSendMessage:(WebSocket*)webSocket;
- (void)webSocketDidSecure:(WebSocket*)webSocket;
@end
typedef enum {
WebSocketStateDisconnected,
WebSocketStateConnecting,
WebSocketStateConnected,
} WebSocketState;
@interface WebSocket : NSObject {
id<WebSocketDelegate> delegate;
NSURL *url;
AsyncSocket *socket;
WebSocketState state;
BOOL secure;
NSString *origin;
NSData *expectedChallenge;
NSArray* runLoopModes;
}
@property(nonatomic,assign) id<WebSocketDelegate> delegate;
@property(nonatomic,readonly) NSURL *url;
@property(nonatomic,retain) NSString *origin;
@property(nonatomic,readonly) WebSocketState state;
@property(nonatomic,readonly) BOOL secure;
@property(nonatomic,retain) NSData *expectedChallenge;
@property(nonatomic,retain) NSArray *runLoopModes;
+ (id)webSocketWithURLString:(NSString *)urlString delegate:(id<WebSocketDelegate>)delegate;
- (id)initWithURLString:(NSString *)urlString delegate:(id<WebSocketDelegate>)delegate;
- (void)open;
- (void)close;
- (void)send:(NSString*)message;
// Deprecated:
- (BOOL)connected; // Returns state==WebSocketStateConnected
@end
enum {
WebSocketErrorConnectionFailed = 1,
WebSocketErrorHandshakeFailed = 2
};
extern NSString * const WebSocketException;
extern NSString * const WebSocketErrorDomain;