Hi.
I need to broadcast message at a specific port to all devices, that are in my LAN.
I have done that on Android just by sending message to 255.255.255.255:PORT. This is my obj-c code, which does not seems to work :
Code:
-(void) initNetworkCommunication
{
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"255.255.255.255", 8888, &readStream, &writeStream);
inputStream = objc_unretainedObject(readStream);
outputStream = objc_unretainedObject(writeStream);
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
[self sendMessage];
}
-(void) sendMessage
{
NSString *response = [NSString stringWithFormat:@"Ping"];
NSData *data = [[NSData alloc] initWithData:[response dataUsingEncoding:NSASCIIStringEncoding]];
[outputStream write:[data bytes] maxLength:[data length]];
}
If i type some real IP (192.168.X.X) everything works fine ..
So .. is there a way to broadcast message to all the devices with an iOS