react-native-udp/UdpSocketClient.h

86 lines
2.3 KiB
C
Raw Normal View History

2015-05-09 21:55:49 +00:00
//
// RCTUDPClient.h
// react-native-udp
//
// Created by Mark Vayngrib on 5/9/15.
// Copyright (c) 2015 Tradle, Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "RCTBridgeModule.h"
extern NSString *const RCTUDPErrorDomain;
enum RCTUDPError
{
RCTUDPNoError = 0, // Never used
RCTUDPInvalidInvocationError,// Invalid method invocation
RCTUDPBadConfigError, // Invalid configuration
RCTUDPBadParamError, // Invalid parameter was passed
RCTUDPSendTimeoutError, // A send operation timed out
RCTUDPSendFailedError, // A send operation failed
RCTUDPClosedError, // The socket was closed
RCTUDPOtherError, // Description provided in userInfo
};
typedef enum RCTUDPError RCTUDPError;
2015-05-10 14:26:29 +00:00
@class UdpSocketClient;
2015-05-09 21:55:49 +00:00
@protocol SocketClientDelegate <NSObject>
2015-05-10 14:26:29 +00:00
- (void)onData:(UdpSocketClient*) client data:(NSData *)data host:(NSString*) host port:(uint16_t) port;
2015-05-09 21:55:49 +00:00
@end
2015-05-10 14:26:29 +00:00
@interface UdpSocketClient : NSObject
2015-05-09 21:55:49 +00:00
@property (nonatomic, retain) NSString* id;
@property (nonatomic, retain) NSString* host;
@property (nonatomic) u_int16_t port;
///---------------------------------------------------------------------------------------
/// @name Class Methods
///---------------------------------------------------------------------------------------
/**
* Initializes a new RCTUDPClient
*
* @param delegate The object holding the callbacks, usually 'self'.
*
* @return New RCTUDPClient
*/
+ (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)bind:(u_int16_t) port address:(NSString*) address error:(NSError**)error;
/**
* send data to another host and port
*
* @param port
* @param host ip address
*/
- (void)send:(NSData*) data remotePort:(u_int16_t) port remoteAddress:(NSString*) address callback:(RCTResponseSenderBlock) callback;
/**
* @return { address: ip, port: port }
*/
- (NSDictionary *)address;
/**
* close client
*/
- (void)close;
@end