Merge pull request #30 from jmc420/master

add multicast
This commit is contained in:
Andy Prock 2016-12-14 14:26:08 -08:00 committed by GitHub
commit 19699c1fa2
3 changed files with 46 additions and 2 deletions

View File

@ -65,6 +65,22 @@ typedef enum RCTUDPError RCTUDPError;
*/
- (BOOL)bind:(u_int16_t) port address:(NSString*) address error:(NSError**)error;
/**
* 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;
/**
* send data to another host and port
*

View File

@ -110,6 +110,24 @@ NSString *const RCTUDPErrorDomain = @"RCTUDPErrorDomain";
return result && [_udpSocket beginReceiving:error];
}
- (BOOL)joinMulticastGroup:(NSString *)address error:(NSError **) error
{
if(![_udpSocket joinMulticastGroup:address error:&error]){
NSLog(@"Error joining multicast group: %@", error);
return false;
}
return true;
}
- (BOOL)leaveMulticastGroup:(NSString *)address error:(NSError **) error
{
if(![_udpSocket leaveMulticastGroup:address error:&error]){
NSLog(@"Error leaving multicast group: %@", error);
return false;
}
return true;
}
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didSendDataWithTag:(long)msgTag
{
NSNumber* tagNum = [NSNumber numberWithLong:msgTag];

View File

@ -106,12 +106,22 @@ RCT_EXPORT_METHOD(setBroadcast:(nonnull NSNumber*)cId
RCT_EXPORT_METHOD(addMembership:(nonnull NSNumber*)cId
multicastAddress:(NSString *)address) {
/* nop */
UdpSocketClient *client = _clients[cId];
if (!client) return;
NSError *error = nil;
[client joinMulticastGroup:address error:&error];
}
RCT_EXPORT_METHOD(dropMembership:(nonnull NSNumber*)cId
multicastAddress:(NSString *)address) {
/* nop */
UdpSocketClient *client = _clients[cId];
if (!client) return;
NSError *error = nil;
[client leaveMulticastGroup:address error:&error];
}
- (void) onData:(UdpSocketClient*) client data:(NSData *)data host:(NSString *)host port:(uint16_t)port