Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-11-2012, 01:35 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 3
savage309 is on a distinguished road
Default Broadcast message to LAN

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
savage309 is offline   Reply With Quote
Old 01-11-2012, 01:47 PM   #2 (permalink)
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 75
newDev is on a distinguished road
Default

Maybe this will help:
RSU: iPhone Programming: Creating Network Socket Connections
__________________
Sir Charles Barkley
newDev is offline   Reply With Quote
Old 01-11-2012, 02:09 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 3
savage309 is on a distinguished road
Default

Nope.
I do basically the same. The point is that I want to send message not to a specific IP address, but to all devices in the local network ..
savage309 is offline   Reply With Quote
Old 01-11-2012, 02:25 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 3
savage309 is on a distinguished road
Default

Sorry, I am an idiot.
255.255.255.255 send to everybody ELSE and since Im testing on ONE MAC I don't receive the message
But it should work .. will write later if this theory gets confirmed.
savage309 is offline   Reply With Quote
Old 01-11-2012, 09:00 PM   #5 (permalink)
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 75
newDev is on a distinguished road
Default

Is the port on the mac accepting incoming messages? I dont think you can send a message to a device that isn't open to accepting it. I have done something like this with a mini python chat server.
__________________
Sir Charles Barkley
newDev is offline   Reply With Quote
Reply

Bookmarks

Tags
lan, message, server, socket

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 388
10 members and 378 guests
7twenty7, Atatator, buggen, guusleijsten, j.b.rajesh@gmail.com, QuantumDoja, sacha1996, Sami Gh, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:38 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0