Peer to peer via ip address for iOS - ios

I have ip addresses of two different iOS Devices which are connected to Internet. Now, I want to establish a peer-to-peer connection between them.
I had done this locally with Wifi and it worked properly. But I dont know how to establish this connection with an IP address. I want that I can connect them from anywhere, so I need to connect via Ip address. Also, is this possible without developing any server? Please help. Thanks.

I couldn't find any exact solution for this problem but one approach could be you can have two ios devices connected with a network having same public IP.
So indirectly both ios devices will be connected to the same network.

What you had done with wifi is probably an Ad-Hoc connection. Ad-Hoc is when you connect 2 wifi devices without any Access Point in the between.
You do not have to do that on the Internet, your devices are already connected to a network. What you need to do is to find out what their IP addresses are and provide them to eachother.
In case your iOS devices are NATed behind a router, you must forward the port which you want to use from the router to the iOS device.
Here are guides for port forwarding for all the existing routers: http://portforward.com/

Related

Connect to a peer based on IP address and port

I've got an app that supports Bonjour and manually connecting to an IP (all within the same local network). I'm now looking at whether I can use MPC instead and while it obviously would be able to replace Bonjour, I haven't seen anything that allows me to replace the functionality around manually connecting to the IP. For context, my app runs in networks that have multicast disabled which is when users fall back to manually entering the IP address.
I could have the receiving app host a webserver and send a request there. Could I create a Peer based on the ip:port combination? That would allow me to make use of MPC for the MCSession aspect.
Is it possible to set up a Multipeer Connection based on an ip:port rather than having it automatically discovered via multicast?
I'll go with a solution based on NWConnection which uses NWEndpoint and can be created with both IP:port and a Bonjour-established service.
If I would've had access to the full Network.framework then I could've used that for both discovery & communication but due to SDK constraints I'll be using MultipeerConnectivity for the discovery aspect instead. By providing the device its IP & port when broadcasting the Bonjour service, another device can discover it automatically and then use the extra info to create an IP:port-based NWConnection.

Accessing remotely my web service

I have implemented a web service on my mac and I am able to access its functionalities through the url "http://localhost:8080/ServiceApp-war/resources/".
As I got satisfying results that I could see in the iPhone simulator in Xcode, I decided to connect my iPhone and test on it. But for this to work I think I need to change the "localhost" in my URL to the IP address of my mac.
I tried to replace it with my public IP address and I got a "could not connect to the server" error on my console. I also tried to replace "localhost" with the IP address I found in System Preferences-->Network-->Wi-Fi and I could see that it was working on the simulator but still nothing when I connect my iPhone and run the application on it.
Please provide a solution for accessing my web service remotely.
Thank you.
Create hotspot from your mac, connect to it with your iPhone and try again.
<lame solution>
Try some service for temporary domain, it will make your computer accessible from anywhere.
How do you "connect" your iPhone? USB connection does not create a network. Well, it does create if you turn on Personal Hotspot on your iPhone (maybe in some other cases, dunno). But the most simple way is to connect Mac and iPhone to the same WiFi network.
Once connected, you can use any of "ping" apps available on App Store. Just look for "ping" (some kind of "network reachability test" or so). You can check if your Mac is really reachable on the network.
If it's not reachable, check your network settings on both devices: do they belong to the same subnet, do they use the same gateway, etc.
If your Mac is reachable with ping, then you should deal with your web service. I setup the web server (which is already distributed within OS X): it already has all the settings to allow other devices to connect. But your web service may require some additional setup. It's two basic things: it should bind to your IP address (please check http://YOUR.IP:8080/ServiceApp-war/resources/ from your Mac!) and second, accept incoming connections from other agents, you should find it somewhere in its settings.
Ngrok was the perfect solution I was looking for.
https://ngrok.com
You could also try finch, which is similar to ngrok. It has a nice friendly GUI. https://meetfinch.com

Access devices from iOS in same network but different subnet

I'm making a network analyzer tool in iOS, and it finds other devices in the same subnet (192.168.1.x) just fine using ping.
But there are more switches and access points connected to the same router, that have different static ips like 10.100.100.x. I would like to ping those to see if they are still awake. I know their ip addresses, I just don't know if they are alive.
How can I ping/probe/nudge devices on the same network but different subnet? Is this possible at all from iOS? Can I perhaps reach them using their mac addresses?

Communicate an iOS device with a non iOS device via WIFI

I am working on a project in which I should connect an iPhone to an accessory via WIFI.
Some blogs spoke about ExternalAccessory.framework but this one is used for establishing connection via Bluetooth.
What library should I use to achieve this ? Could any one please point me to the right direction ? Thanks.
(Assuming that you don't know the ip address of the device you want to connect to)
From an iOS standpoint you want to use NSNetService to discover devices on the network which you can connect to.
This requires that your other device can use mdnsresponder to publish its details onto the network such that it can be found and connected to.
If you do know the ip address (or, once you do know it) then you can use NSURLConnection / NSStream to connect to the device (depending on what capabilities it offers).

Connect iPhone to local server for testing on XCode? -- without using WiFi

So I have an ejabberd (XMPP) server setup on my MacBook. Connects fine with Simulator, only intermittently on the device. The two times it hasn't connected were at cafes that had sign-on gateways for their Wi-Fi. I know nothing when it comes to networks, but I'm guessing this is a Firewall thing?
I'm supposing I can't get around the firewall without an elaborate workaround.
I've found that turning off Wi-Fi on both devices and turning on tethering so that both devices are communicating via data works. However, I'd rather not do this as my data plan is limited and I'd like to be freely internet-connected while I work.
Is there a way to setup XCode to have the phone use the USB connection to access the server on the MacBook? Or maybe some other way I'm not imagining?
Bluetooth doesn't work.
I don't believe that the problem is with some kind of firewall on the network…
Try using the local IP address instead of the hostname, It will change from network to network. To get it, you can open the network utility
In this case it would be [xmppStream setHostName:#"172.16.1.2"];

Resources