react-native-udp/ios/UdpSocketClient.h

109 lines
2.9 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>
2017-02-10 04:23:08 +00:00
#import <React/RCTBridgeModule.h>
2015-05-09 21:55:49 +00:00
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;
@property (nonatomic, weak) id<SocketClientDelegate> clientDelegate;
2015-05-09 21:55:49 +00:00
///---------------------------------------------------------------------------------------
/// @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
* @param options (such as 'reusePort')
2015-05-09 21:55:49 +00:00
* @return true if bound, false if there was an error
*/
- (BOOL)bind:(u_int16_t) port address:(NSString*)address options:(NSDictionary *)options error:(NSError**)error;
2015-05-09 21:55:49 +00:00
2016-11-10 17:49:33 +00:00
/**
* Join multicast groupt
*
* @param address
* @return true if joined, false if there was an error
*/
- (BOOL)joinMulticastGroup:(NSString *)address error:(NSError **) error;
/**
* leave multicast groupt
*
* @param address
* @return true if joined, false if there was an error
*/
- (BOOL)leaveMulticastGroup:(NSString *)address error:(NSError **) error;
2015-05-09 21:55:49 +00:00
/**
* 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;
2015-07-29 16:16:01 +00:00
/**
* Enable broadcast
*/
- (BOOL)setBroadcast:(BOOL) flag error:(NSError **) error;
2015-05-09 21:55:49 +00:00
@end