Check internet connection in iPhone - not just to router - objective-c

I use the normal Reachability tools to check if there is an internet connection available. It works in most cases, but if I unplug the WAN cable to the wifi-router, for some reason it still say it can find the host by wifi. If I change the web address to something that doesn't exists, it will say "The internet is down", like it should. Where is my problem?
Example:
I. I have the "internet cable" unplugged, but phone connected by wifi to router. I run with this line, the first time for this domain:
hostReachable = [[Reachability reachabilityWithHostName: #"www.google.com"] retain];
Result = No host found (correct)
II. I disable wifi in the phone. Result = Host found with WWAN (correct)
III. I enable wifi in the phone. Result = Host found with WIFI. (not correct, since router is not online)

For internet checking I send an http request to one site(most probably google.com) if it does not return true, it means no internet. This case works even the connection is so slow. Here is the method.
- (BOOL) connectedToInternet
{
NSString *URLString = [NSString stringWithContentsOfURL:[NSURL URLWithString:#"http://www.google.com"]];
return ( URLString != NULL ) ? YES : NO;
}

You may want to check out this thread. The Reachability code is known to only test connectivity with your router. There should be a notification for connectivity now.

Related

How to access with my mobile to an app that use an api that is host in localhost

Im using an api in order to login in my ionic app.
It works as normal but when I use it in my phone it doesn't work.
When I'm trying to do it, an error appears to the console
E/Capacitor/Console: File: http://localhost/vendor.js - Line 70452 - Msg: ERROR [object Object]
This is how I use my api
var url2 = "http://localhost:3625/api/Filters/LoginEmployee";
Im trying to change a line that allows the connection in Manifest but it doesn't work.
When you run the APP inside your phone, the http://localhost/vendor.js should be changed to the IP of the computer where the API is running.
If you are testing probably the server is your machine, put both devices, the phone and the computer in the same network to make both available to ping each other.
Verify if your access point is not blocking the 3625 port in the local network.

Akka.Net Remoting Configuration + Association questions

we just upgraded Akka.Net to 1.1.3 from 1.0.7 and noticed that remoting HOCON had a few new properties such that the following works on Azure, but doesn't on private dedicated servers (say a GoDaddy box):
akka {
actor { provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote"" }
remote {
helios.tcp {
port = 0
hostname = 0.0.0.0
dns-use-ipv6 = false
public-hostname = localhost
enforce-ip-family = true
}
}
}
And the following works well on dedicated servers, but not on Azure:
akka {
actor {
provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
}
remote {
helios.tcp {
port = 0
hostname = 0.0.0.0
dns-use-ipv6 = false
public-hostname = localhost
enforce-ip-family = false
}
}
}
From the documentation in the change logs that I found, it appears that enforce-ip-family is a setting which when set to TRUE would allow forcing a client to use IPv6 by setting dns-use-ipv6 to true.
Is this a correct interpretation on my part? Is there some documentation regarding these settings that we could read?
Also, let's say that I wanted to use IPv6 on Azure, what would the server configuration be? Is this even something that I could control?
I also noticed something with the new version that I hadn't noticed before, overnight, I started getting these exceptions:
Tried to associate with unreachable remote address
[akka.tcp://TestActorSystem#localhost:51675]. Address is now gated for
5000 ms, all messages to this address will be delivered to dead
letters. Reason: [No connection could be made because the target
machine actively refused it.
We hadn't seen these errors before and it really doesn't look like there's a specific reason on this before the first one started. Has anyone else experienced this? Could any one shed some light on what I could do to gracefully resolve this situation? A critical piece of functionality stopped working because of this issue and we're trying to figure out how to best address it.
Please pardon my lack of expertise on Akka 1.1.3 but I think I had it all figured out until I inadvertently upgraded the nuget package and had a rude awakening :)
Thank You,
Anup

WEBRTC, not working between different nets

I'm developing a simple app that uses webrtc for transmitting real-time video in one direction (one sender and one receiver). It uses socket.io and node.js for the signalling.
At this moment, it's albe to transmit real-time video when the sender and receiver are in the same net (the server is already online), but if I use mobile net or if the peers are connected in different wifis it doesn´t work.
Actually, I make a test using public library's wifi and my home wifi and when the sender was in the public wifi it worked.
The message I get in firefox when it fails is :
ICE failed, see about:webrtc for more details
As I've read, webrtc uses STUN/TURN servers to solve problems with net's NATS. I have introduced urls from a STUN and a TURN server but it seems it had no effect.
This is the way I'm 'using' the STUN/TURN servers:
var configuration = { iceServers: [
{
urls: "turn:numb.viagenie.ca",
username: "xxxxxxxx#hotmail.com",
credential: "********"
},
{
urls: "stun:stun.callwithus.com"
}
]};
var pc = new RTCPeerConnection(configuration);
For both sides the same and it seems the servers are up.
So, my final question is, I need to do something else to make sure webrtc is using STUN/Turn servers when it's needed?
Or, do you know any other possible cause for this behaviour?
Everything you know can help a lot, because i couldn't find how to use those servers.
if you need more information, please ask for it.
T
Yes, you need to listen to pc.onicecandidate and send each candidate over your signaling channel to the other side, where you call pc.addIceCandidate with it like this, if using adapter.js:
pc.addIceCandidate(candidate).catch(e => console.log(e))
or like this if not (older syntax):
pc.addIceCandidate(new RTCIceCandidate(candidate)).catch(e => console.log(e))
You can also dump the ICE candidates to see if your settings work (srflx = stun, relay = turn):
var PC = window.RTCPeerConnection || window.webkitRTCPeerConnection;
var server = { urls: "stun:stun.l.google.com:19302" };
var pc = new PC({ iceServers: [server] });
pc.onicecandidate = e => e.candidate && console.log(e.candidate.candidate);
pc.createDataChannel("dummy");
pc.createOffer().then(d => pc.setLocalDescription(d)).catch(e => console.log(e));
You can modify that snippet to include your turn server.
console logs of failed comunication
That's an example of what I get in the console. It seems srflx and relay are used, but at some point I get a null candidate, the error on screenshot is because of i'm trying to log a 'candidate' property of a null object.
Finally, the problem was solved.
It seems that Turn server wasn't working fine. I made a trial account on xyrsis and changed the stun and turn servers and it was solved.
Thank you all.

NSMutableURLRequest cannot connect to local network

I am using AFNetworking to connect from an iOS v6.0 app to my local Cold Fusion 8 server, not on the same machine but on the same network and the connection times out. When I use an external public server it works fine.
I have tried the connection via IP address and it doesn't work.
I have tried an entry in the hosts file assigning a domain name to the IP address and this doesn't work either. Please see the error below.
I can however connect via a web browser just fine.
Also, the server side files are exactly the same. Versions of Cold Fusion are the same. The only difference that I can find are the public server is Win2003 with IIS6 and the local server is Windows7 with IIS7.
Any thoughts on why this would not work on a local network. Makes local development kind of difficult.
Here is the relevant code:
// load params
NSMutableDictionary *myParams = [[NSMutableDictionary alloc] init];
[myParams setValue:#"Hello" forKey:#"Parameter1"];
[myParams setValue:#"There" forKey:#"Parameter2"];
// Load the base URL into a URL object
// Changing this to an external public server works fine
NSURL *baseURL = [NSURL URLWithString:#"http://www.mylocalmachine.com/"];
// Create HTTP client and init with base url
AFHTTPClient *myHttpClient = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
// POST request to path with the parameters
NSMutableURLRequest *myRequest = [myHttpClient requestWithMethod:#"POST" path:#"myfile.cfm" parameters:myParams];
// Block response from the HTTP client request and pass it back to the calling object
AFJSONRequestOperation *myOperation = [AFJSONRequestOperation JSONRequestOperationWithRequest:myRequest
success:^(NSURLRequest *mySuccessRequest, NSHTTPURLResponse *mySuccessResponse, id mySuccessJSON)
{
// PROCESS THE SUCCESS RESPONSE;
}
failure:^(NSURLRequest *myFailureRequest, NSHTTPURLResponse *myFailureResponse, NSError *myFaliureError, id myFailureJSON)
{
// PROCESS THE FAILURE RESPONSE... AFTER 60 seconds the system will fallout to this block.
}];
// Create a queue object
NSOperationQueue *myQueue = [[NSOperationQueue alloc] init];
// Add the operation object to the queue
[myQueue addOperation:myOperation];
The following is the error I get print the myFailureError object
Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x8481000 {NSErrorFailingURLStringKey=http://www.mylocalmachine.int/myfile.cfm, NSErrorFailingURLKey=http://www.mylocalmachine.int/myfile.cfm, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x9189e20 "The request timed out."}
Update----
I believe I have narrowed the issue down to what I beleive to be an issue with the iPhone simulator accessing IIS 7. It will access previous versions of IIS on the same network using the same code no problem.
The problem may be in the iPhone Simulator's User-Agent. I have tried to find a way to change the iPhone Simulator's User-Agent or allow the User-Agent in IIS 7 but can not seem to figure it out. The User-Agent the iPhone Simulator 6 is presenting is (iPhone Simulator; ios 6.0; Scale/2.00).
Does anyone know how to either allow this User-Agent on IIS 7 or change the User-Agent in the iPhone simulator?
Has anyone else seen this issue?
Thanks in advance,
Ed
Update----
Hi Everyone
Ok so I figured out how to change the User-Agent and Content-Type using the NSMutableURLRequest. I changed these to match what the browser would send, FireFox browser, and tried again to no avail. I still believe there is an issue with the configuration of IIS 7.5 but I can not find it...
Thanks for anyones help!!!
Ed
please try to remove last 2 lines of code and write
remove this
NSOperationQueue *myQueue = [[NSOperationQueue alloc] init];
[myQueue addOperation:myOperation];
add this instead
[myoperation start];
and also write failure:nil before that ending square bracket(]) like
AFJSONRequestOperation *myOperation = [AFJSONRequestOperation JSONRequestOperationWithRequest:myRequest
success:^(NSURLRequest *mySuccessRequest, NSHTTPURLResponse *mySuccessResponse, id mySuccessJSON)
{
// PROCESS THE SUCCESS RESPONSE;
}
failure:^(NSURLRequest *myFailureRequest, NSHTTPURLResponse *myFailureResponse, NSError *myFaliureError, id myFailureJSON)
{
// PROCESS THE FAILURE RESPONSE... AFTER 60 seconds the system will fallout to this block.
}failure:nil];
let me know is it working or not...!!!!
Happy Coding!!!!!!
I have resolved this issue. I will post what the resolution was to hopefully help someone else with a similar issue.
Turns out the problem was AVG installed on the system that was running IIS 7. It was a difficult issue to determine because any other system could access the web server with out any problems. It was only specific with the iPhone simulator accessing the system running IIS7. Even Safari or FireFox running on the same Mac would work just fine. Now what within AVG was causing the problem... That is yet to be determined.
I truly hope this helps someone along the way!

How to get all available hostnames and associated IP addresses on LAN using Obj C on Mac OS X?

I have a requirement to get the list of IP addresses of all the machines connected to LAN. I created an NSHost object and used it to get addresses of current host and it worked fine. But I need to get addresses of all other hosts on the network.
Any helpful answer would be appreciable. Thanks in advance.
my snippet:
NSHost* host = [NSHost currentHost];
NSString* myIPAddress = [NSString stringWithFormat:
[[host addresses] objectAtIndex:1]];
executing this gave myIPAddress as 192.168.1.202 which is correct.
That's not necessarily knowable, and depends on collusion with the other hosts. You might consider determining your broadcast address (e.g. 192.168.1.255), sending an ICMP echo request and then enumerating the responses: but a system that doesn't respond to the request won't show up. Similar problems are apparent when using responses to any other request: port scans or mDNS registrations.