2015-12-04 09:44:16 -08: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 11:45:33 -08:00
|
|
|
extern NSString *const RCTTCPErrorDomain;
|
2015-12-04 09:44:16 -08:00
|
|
|
|
2015-12-07 11:45:33 -08:00
|
|
|
enum RCTTCPError
|
2015-12-04 09:44:16 -08:00
|
|
|
{
|
2015-12-07 11:45:33 -08: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 09:44:16 -08:00
|
|
|
};
|
|
|
|
|
2015-12-07 11:45:33 -08:00
|
|
|
typedef enum RCTTCPError RCTTCPError;
|
2015-12-04 09:44:16 -08:00
|
|
|
|
|
|
|
@class TcpSocketClient;
|
|
|
|
|
|
|
|
@protocol SocketClientDelegate <NSObject>
|
|
|
|
|
|
|
|
- (void)onData:(TcpSocketClient*) client data:(NSData *)data;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface TcpSocketClient : NSObject
|
|
|
|
|
|
|
|
@property (nonatomic, retain) NSString* id;
|
|
|
|
@property (nonatomic, retain) NSString* host;
|
|
|
|
@property (nonatomic) u_int16_t port;
|
|
|
|
|
|
|
|
///---------------------------------------------------------------------------------------
|
|
|
|
/// @name Class Methods
|
|
|
|
///---------------------------------------------------------------------------------------
|
|
|
|
/**
|
2015-12-07 11:45:33 -08:00
|
|
|
* Initializes a new RCTTCPClient
|
2015-12-04 09:44:16 -08:00
|
|
|
*
|
|
|
|
* @param delegate The object holding the callbacks, usually 'self'.
|
|
|
|
*
|
2015-12-07 11:45:33 -08:00
|
|
|
* @return New RCTTCPClient
|
2015-12-04 09:44:16 -08: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
|
|
|
|
*/
|
|
|
|
- (BOOL)connect:(u_int16_t) port host:(NSString*) host error:(NSError**)error;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* write data
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
- (void)writeData:(NSData*) data callback:(RCTResponseSenderBlock) callback;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* close client
|
|
|
|
*/
|
|
|
|
- (void)close;
|
|
|
|
|
|
|
|
|
|
|
|
@end
|