2015-12-04 17:44:16 +00:00
|
|
|
//
|
|
|
|
// TcpSocketClient.h
|
|
|
|
// react-native-tcp
|
|
|
|
//
|
|
|
|
// Created by Andy Prock on 12/14/15.
|
|
|
|
// Copyright (c) 2015 Peel, Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import "RCTBridgeModule.h"
|
|
|
|
|
2015-12-07 19:45:33 +00:00
|
|
|
extern NSString *const RCTTCPErrorDomain;
|
2015-12-04 17:44:16 +00:00
|
|
|
|
2015-12-07 19:45:33 +00:00
|
|
|
enum RCTTCPError
|
2015-12-04 17:44:16 +00:00
|
|
|
{
|
2015-12-07 19:45:33 +00:00
|
|
|
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
|
2015-12-04 17:44:16 +00:00
|
|
|
};
|
|
|
|
|
2015-12-07 19:45:33 +00:00
|
|
|
typedef enum RCTTCPError RCTTCPError;
|
2015-12-04 17:44:16 +00:00
|
|
|
|
|
|
|
@class TcpSocketClient;
|
|
|
|
|
|
|
|
@protocol SocketClientDelegate <NSObject>
|
|
|
|
|
2015-12-15 00:16:45 +00:00
|
|
|
- (void)onConnect:(TcpSocketClient*) client;
|
2015-12-04 17:44:16 +00:00
|
|
|
- (void)onData:(TcpSocketClient*) client data:(NSData *)data;
|
2015-12-15 00:16:45 +00:00
|
|
|
- (void)onClose:(TcpSocketClient*) client withError:(NSError *)err;
|
|
|
|
- (void)onError:(TcpSocketClient*) client withError:(NSError *)err;
|
2015-12-04 17:44:16 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface TcpSocketClient : NSObject
|
|
|
|
|
2015-12-15 00:16:45 +00:00
|
|
|
@property (nonatomic, retain) NSString * id;
|
|
|
|
@property (nonatomic, retain) NSString * host;
|
2015-12-04 17:44:16 +00:00
|
|
|
@property (nonatomic) u_int16_t port;
|
|
|
|
|
|
|
|
///---------------------------------------------------------------------------------------
|
|
|
|
/// @name Class Methods
|
|
|
|
///---------------------------------------------------------------------------------------
|
|
|
|
/**
|
2015-12-07 19:45:33 +00:00
|
|
|
* Initializes a new RCTTCPClient
|
2015-12-04 17:44:16 +00:00
|
|
|
*
|
|
|
|
* @param delegate The object holding the callbacks, usually 'self'.
|
|
|
|
*
|
2015-12-07 19:45:33 +00:00
|
|
|
* @return New RCTTCPClient
|
2015-12-04 17:44:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
+ (id)socketClientWithConfig:(id<SocketClientDelegate>) delegate;
|
|
|
|
|
|
|
|
///---------------------------------------------------------------------------------------
|
|
|
|
/// @name Instance Methods
|
|
|
|
///---------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* Binds to a host and port
|
|
|
|
*
|
|
|
|
* @param port
|
|
|
|
* @param host ip address
|
|
|
|
* @return true if bound, false if there was an error
|
|
|
|
*/
|
2015-12-15 00:16:45 +00:00
|
|
|
- (BOOL)connect:(NSString *)host port:(int)port withOptions:(NSDictionary *)options error:(NSError **)error;
|
2015-12-04 17:44:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* write data
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
- (void)writeData:(NSData*) data callback:(RCTResponseSenderBlock) callback;
|
|
|
|
|
|
|
|
/**
|
2015-12-15 00:16:45 +00:00
|
|
|
* end client
|
2015-12-04 17:44:16 +00:00
|
|
|
*/
|
2015-12-15 00:16:45 +00:00
|
|
|
- (void)end;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* destroy client
|
|
|
|
*/
|
|
|
|
- (void)destroy;
|
2015-12-04 17:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
@end
|