Test to see if a server is online using IP address
I'm trying to write a method to test the availability of a radio stream
server using it's IP address and the Reachability framework. I've tried
using the ReachabilityWithAddress method so that I can use an IP address
instead of a domain name. The problem is that the method never runs all
the way through, it stops before it tests the reachability of the server.
(//Server is reachable part of the code)
I have a method which detects there is an internet connection by using
ReachabilityWithHostName, this should work in the same way, but use
ReachabilityWithAddress
Any ideas?
-(void)testServerConnection
{
struct sockaddr_in serverAddress;
serverAddress.sin_len = sizeof(serverAddress);
serverAddress.sin_family = AF_INET;
serverAddress.sin_port = htons(48266);
serverAddress.sin_addr.s_addr = inet_addr("50.115.124.197");
internetReachableFoo = [Reachability reachabilityWithAddress:&serverAddress];
//Server is reachable
internetReachableFoo.reachableBlock = ^(Reachability *reach)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"The server is available");
});
};
//An error message is shown if the server is unavailable
internetReachableFoo.unreachableBlock = ^(Reachability *reach)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"The server is unavailable");
UIAlertView *noServerConnectionAlert = [[UIAlertView alloc]
initWithTitle:@"Connection Error" message:@"The server is
currently offline, check the schedule for more information"
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[noServerConnectionAlert show];
});
};
[internetReachableFoo startNotifier];
}
No comments:
Post a Comment