3

Is it possible to build a socket connection between 2 iOS devices connected to the same network (Without net)?

if it's possible .. Is (CocoaAsyncSocket project) useful for me?

I just want to send a message from Device A to Device B which put the app in background .. when Device B receive the message should show notification to return the app to foreground.

It's not for the App Store, so I don't care if Apple would reject the app because of this behavior.

Nate
  • 31,017
  • 13
  • 83
  • 207
Husam
  • 8,149
  • 3
  • 38
  • 45
  • I'm looking at another question of yours ... for this problem, do you also want to make the connection over wifi, without access to the carrier's network? – Nate Sep 16 '12 at 21:06
  • I just want to use a local network like **ad-hoc** but without internet signal if possible ... thanks Nate for that quick response – Husam Sep 16 '12 at 21:30

1 Answers1

3

Yes, you can do it, and yes, CocoaAsyncSocket would be useful. If you don't have to worry about the carrier network's firewalls and filters, then you should certainly be able to build a client-server app running on two iOS devices. One opens the server socket to listen, and the other one (the client) connects, via the Wi-Fi network.

Trying searching on Google (e.g. "CocoaAsyncSocket iPhone iOS site:stackoverflow.com") or directly here on Stack Overflow.

Here's somebody who seems to have accomplished this

Another link

And a post from Robbie Hanson himself, referring you to the EchoServer projects in the github repository

EchoServer project

You may have to use a static IP address for the server device (I'm not sure how much control you have over the Wi-Fi network's configuration), or use some other mechanism for letting the two devices discover each other.

Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207
  • Your words helped me ,I built a client-server app successfully as your advice , I used `GCDAsyncSocket`... but I faced another problem :( – Husam Sep 19 '12 at 17:10
  • the listener device couldn't read data received in background until it be foreground ... in other words It's delegate freeze's in background mode .. I want to read data received in background in order to show local notification contains (Show App) button XD ... do u have any idea to fix ? thank u – Husam Sep 19 '12 at 17:19
  • 1
    @Husam, I believe iOS shuts down sockets when your app goes to the background. since you said this is not for the app store, [you could try this solution](http://stackoverflow.com/a/6000223/119114). basically, it has your app *pretend* to be a `voip` app, which would allow it to keep network connections even in the background. I think you might need to add a *background task* to make this work ... see the link provided. alternatively, if you are able to jailbreak the phone , then you could [build the app as a Launch Daemon](http://chrisalvares.com/blog/7/creating-an-iphone-daemon-part-1/) – Nate Sep 19 '12 at 18:36
  • I found an easy solution ...I will install **Backgrounder** from Cydia to keep the app alive in background .. Thanks, u made a huge favor for me. – Husam Sep 19 '12 at 19:20
  • @Husam, great. I'm glad it worked out. You certainly can do a lot of great things with an iPhone if it's jailbroken! – Nate Sep 19 '12 at 20:35