-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathTcpSocketClient.h
144 lines (112 loc) · 4.13 KB
/
TcpSocketClient.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#import "CocoaAsyncSocket/GCDAsyncSocket.h"
#import <React/RCTBridgeModule.h>
extern NSString *const RCTTCPErrorDomain;
enum RCTTCPError {
RCTTCPNoError = 0, // Never used
RCTTCPInvalidInvocationError, // Invalid method invocation
RCTTCPBadConfigError, // Invalid configuration
RCTTCPBadParamError, // Invalid parameter was passed
RCTTCPSendTimeoutError, // A send operation timed out
RCTTCPSendFailedError, // A send operation failed
RCTTCPClosedError, // The socket was closed
RCTTCPOtherError, // Description provided in userInfo
};
typedef enum RCTTCPError RCTTCPError;
@class TcpSocketClient;
// Add ResolvableOption interface here
@interface ResolvableOption : NSObject
@property (nonatomic, strong, readonly) NSString *value;
@property (nonatomic, readonly) BOOL needsResolution;
- (instancetype)initWithValue:(NSString *)value needsResolution:(BOOL)needsResolution;
+ (instancetype)optionWithValue:(NSString *)value needsResolution:(BOOL)needsResolution;
- (NSString *)resolve;
@end
@protocol SocketClientDelegate <NSObject>
- (void)addClient:(TcpSocketClient *)client;
- (void)onConnect:(TcpSocketClient *)client;
- (void)onListen:(TcpSocketClient *)server;
- (void)onConnection:(TcpSocketClient *)client toClient:(NSNumber *)clientID;
- (void)onSecureConnection:(TcpSocketClient *)client
toClient:(NSNumber *)clientID;
- (void)onData:(NSNumber *)clientID data:(NSData *)data;
- (void)onClose:(TcpSocketClient *)client withError:(NSError *)err;
- (void)onError:(TcpSocketClient *)client withError:(NSError *)err;
- (void)onWrittenData:(TcpSocketClient *)client msgId:(NSNumber *)msgId;
- (NSNumber *)getNextId;
@end
@interface TcpSocketClient : NSObject <GCDAsyncSocketDelegate>
@property(nonatomic, retain) NSNumber *id;
@property(nonatomic, weak) id<SocketClientDelegate> clientDelegate;
- (GCDAsyncSocket *)getSocket;
///---------------------------------------------------------------------------------------
/// @name Class Methods
///---------------------------------------------------------------------------------------
/**
* Initializes a new RCTTCPClient
*
* @param delegate The object holding the callbacks, usually 'self'.
*
* @return New RCTTCPClient
*/
+ (id)socketClientWithId:(NSNumber *)clientID
andConfig:(id<SocketClientDelegate>)delegate;
///---------------------------------------------------------------------------------------
/// @name Instance Methods
///---------------------------------------------------------------------------------------
/**
* Connects to a host and port
* @param port port
* @param host ip address
* @param options NSDictionary which can have @"localAddress" and @"localPort"
* to specify the local interface
* @return true if connected, false if there was an error
*/
- (BOOL)connect:(NSString *)host
port:(int)port
withOptions:(NSDictionary *)options
tlsOptions:(NSDictionary *)tlsOptions
error:(NSError **)error;
/**
* Starts listening on a local host and port
*
* @param options NSDictionary which must have a @"port" and @"host" to specify
* where to listen
* @return true if connected, false if there was an error
*/
- (BOOL)listen:(NSDictionary *)options error:(NSError **)error;
/**
* Returns the address information
*
* @return NSDictionary with @"address" host, @"port" port, @"family" IPv4/IPv6
*/
- (NSDictionary<NSString *, id> *)getAddress;
/**
* write data
*
*/
- (void)writeData:(NSData *)data msgId:(NSNumber *)msgId;
- (void)startTLS:(NSDictionary *)tlsOptions;
/**
* end client
*/
- (void)end;
/**
* destroy client
*/
- (void)destroy;
- (void)setNoDelay:(BOOL)noDelay;
- (void)setKeepAlive:(BOOL)enable initialDelay:(int)initialDelay;
- (void)pause;
- (void)resume;
+ (BOOL)hasIdentity:(NSDictionary *)aliases;
/**
* Get peer certificate information
* @return NSDictionary with certificate information or nil if not available
*/
- (NSDictionary *)getPeerCertificate;
/**
* Get local certificate information
* @return NSDictionary with certificate information or nil if not available
*/
- (NSDictionary *)getCertificate;
@end