Connect from ios device to localhost - ios

I have a REST service running on my host. I can perform an HTTP request to this service from my flutter app when running on the iOS simulator using the code below:
final response = await http.get('http://localhost:8085/my/service');
However, it fails when I'm running the app on my iOS device. My device is connected via USB.
Runner[574:66922] flutter: Error SocketException: OS Error: Connection refused, errno = 61, address = localhost, port = 49575
What do I need to configure to connect to localhost from my iOS device?
I've already disabled in iTunes -> Summary "Sync with this iPad over Wi-Fi".

instead of localhost you can use your current ip
to get it In the command window type: ipconfig
Note that you must be on the same network

Related

Flutter cannot run app on iOS device, but iOS simulator and Android working

I wrote app and it's working on Android, Android emulator, iOS emulator but not working on iOS device. It works previously, but I do not test it for a lot of days and now I cannot do it. When I run app, I see splash screen and nothing else happen for a lot of minutes. There is no error, but I see in VSC console:
Connecting to the VM Service is taking longer than expected...
Still attempting to connect to the VM Service...
If you do NOT see the Flutter application running, it might have crashed. The device logs (e.g. from adb or XCode) might have more details.
If you do see the Flutter application running on the device, try re-running with --host-vmservice-port to use a specific port known to be available.
Exception attempting to connect to the VM Service: SocketException: Connection refused (OS Error: Connection refused, errno = 61), address = 127.0.0.1, port = 52448
This was attempt #50. Will retry in 0:00:01.600000.
Exception attempting to connect to the VM Service: SocketException: Connection refused (OS Error: Connection refused, errno = 61), address = 127.0.0.1, port = 52559
This was attempt #100. Will retry in 0:00:01.600000.
Exception attempting to connect to the VM Service: SocketException: Connection refused (OS Error: Connection refused, errno = 61), address = 127.0.0.1, port = 52660
This was attempt #150. Will retry in 0:00:01.600000.

Connect to localhost from iPhone - macOS Monterey

Before updating to Mac OS Monterey I was able to connect to localhost and any port as long as I was on the same internal network. However this no longer seems to be working.
I have also tried to access via xxxx.local which only prints an html page that says "It Works!" which is located in /Library/Documents/WebServer/index.html.en. But if I navigate to any port, things just seem to just hangup.
Steps taken:
System Preference > Network > IP Address
Connect device to same network
Enter in ipaddress:port into browser
Get failed to connect message.
Suggestions?

Web socket fails on iOS

My code attempts to create a websocket connection.
It works on Windows, Mac and Ubuntu and on Safari, Firefox, Chrome and Edge.
It does not work on iOS (iPhone and iPad) and I have tested this failure on Safari and Chrome only. I guess it may not work for other browsers on iOS too.
I get the following error on iPad:
error: Websocket connection to 'wss://XXXX' failed: The operation could not be completed. (kNWErrorDomainPOSIX error 14 - Bad address).
On iPhone it gives a slightly different error:
error: Websocket connection to 'wss://XXXX' failed: The operation could not be completed. kNWErrorDomainPOSIX error 100 - Protocol error.
Where XXXX is a valid network address (domain name / remote IP / local network IP).
Try entering a servers local ip address http://192.168.xx.xx:PORT and make sure both devices are on same local network

Xamarin VS2015 ios app connect to web app api

I have a iOS app that I am building in Visual Studio 2015 with Xamarin. I also have a Web Application with an Api, no authorisation. But when I try to connect to the api I get an error saying "Connection Refused".
I call the api through the following code:
var client = new HttpClient();
var data = await client.GetAsync("http://localhost:7074/api/values/get");
Config your Web API with an IP Address, say local 192.168.x.x
And replace localhost by that IP
var data = await client.GetAsync("http://191.268.x.x:7074/api/values/get");
localhost will point to your iOS device/emulator, not the server. You need to specify the IP or FQDN in the url. Also be be sure the firewall is open and that IIS is setup to accept remote connections.
localhost is your iPhone / iPad or simulator (the device where you run your app). You have to change it to the IP/Domain of your server.
If the server is your dev machine, ensure, that your phone is connected to the same network (e.g. via WiFi), else you might have the same problem, because your dev machine might not be reachable.
You can find the IP of your dev machine by typing ipconfig | find "IPv4" into the console (on Windows).

Able to make a VPN connection from client to the tunnel_server (using apple's SimpleTunnel app) but unable to browse the internet on the device

I built the SimpleTunnel sample app (provided by apple) and am running the VPN client on a IOS device and the VPN server (tunnel_server) on a MAC running OS 10.11 (OS X El Capitan)
On MAC :-
$ sudo ./tunnel_server 550 ../../tunnel_server/config.plist
Response :-
tunnel_server[87725:2604682] Starting network service on port 550
tunnel_server[87725:2604682] Network service published successfully
On IOS device :-
Next I ran the PacketTunnel app on my IOS device. Added a VPN configuration with the correct IP address (the IP address of the MAC running the tunnel_server) and the port number (port number for the tunnel_server which is 550).
Next I try to connect to the VPN from the IO device and this seems to go through fine as I see the VPN sign in status bar.
Response on the screen running tunnel_server :-
tunnel_server[87739:2606312] Accepted a new connection
tunnel_server[87739:2606312] Allocated address Optional("10.8.0.15")
However I am not able to browse the internet using Safari on the IOS device (it times out), but am able to do the same from the MAC.
Any insights on what I might be missing ?
Please note that my MAC doesn't have OS X server installed. Also I did run the following two comands from a terminal before starting the tunnel_server on the MAC
sudo sysctl net.inet.ip.forwarding=1
sudo sysctl net.inet.ip.fw.enable=1

Resources