Skip navigation.
 
mlRe: Detecting Internet
FROM : Gerriet M. Denkmann
DATE : Sat Jul 15 07:57:33 2006

On 15.07.2006, at 03:34, <email_removed> wrote:

> Subject: Re: Detecting Internet
> To: Cocoa Developers <<email_removed>>
> Message-ID: <C0DD7E5D.23E96%<email_removed>>
> Content-Type: text/plain;    charset="US-ASCII"
>
> on 06/07/14 14:06, Gerriet M. Denkmann at <email_removed> wrote:
>

>> On 14.07.2006, at 17:49, Jerry Krinock <<email_removed>> wrote:

>

>>> Create and load an NSURLConnection.  If you're not connected to the
>>> internet, you immediately get an NSURLResponse with a -1009 status
>>> code.

>>
>> Just tried it.... [describes something different]

>
> No, Garriet, you did not try what I said.  Here is some code to get 
> you
> started:
>
> NSURL* url = [NSURL urlWithString:@"http://www.apple.com"] ;
> NSURLRequest* request=[NSURLRequest requestWithURL:url
>                             
> cachePolicy:NSURLRequestReloadIgnoringCacheData
>                      timeoutInterval:65536.0];
> // since timeoutInterval is broken, I set it to a large value and
> // use an "external" NSTimer to time out.
>
> NSURLConnection* connection = [NSURLConnection
>            connectionWithRequest:mutableRequest delegate:self] ;
>


Well, here is the code I used:

- (void)testUrll;
{
   NSURL *theURL = [ NSURL  URLWithString: @"http://www.mdenkmann.de" ];
   NSURLRequest *request = [ NSURLRequest    requestWithURL:        theURL
                                             cachePolicy:        
NSURLRequestReloadIgnoringCacheData
                                               timeoutInterval:    65536.0
                           ];
   BOOL can = [ NSURLConnection canHandleRequest: request ];
   NSLog(@"%s can %d",__FUNCTION__, can);    //    YES
   
   NSURLConnection *cu = [ NSURLConnection connectionWithRequest: 
request delegate: self ];
   NSLog(@"%s cu %@",__FUNCTION__, cu);    
}

- (void)connection:(NSURLConnection *)connection didFailWithError:
(NSError *)error
{
   NSLog(@"%s %@ %@",__FUNCTION__, connection, error);
}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:
(NSURLResponse *)response
{
   NSLog(@"%s %@ %@",__FUNCTION__, connection, response);
}


And here is the result:

Near Phone (and modem not connected):

CurrentSet updated to 145DEEED-18EA-11D8-9597-000A95BBE57C (Near Phone)
2006-07-15 07:46:49.054 EnTeP[2174] -[NetWatcher(NetWatcherPrivate) 
testUrll] can 1
2006-07-15 07:46:49.057 EnTeP[2174] -[NetWatcher(NetWatcherPrivate) 
testUrll] cu <NSURLConnection http://www.mdenkmann.de/>
2006-07-15 07:46:49.187 EnTeP[2174] -[NetWatcher(NetWatcherPrivate) 
connection:didFailWithError:] <NSURLConnection http://
www.mdenkmann.de/> NSError "no Internet connection" 
Domain=NSURLErrorDomain Code=-1009 UserInfo={
    NSErrorFailingURLKey = http://www.mdenkmann.de/;
    NSErrorFailingURLStringKey = "http://www.mdenkmann.de/";
    NSLocalizedDescription = "no Internet connection";
}
Immediate response. Ok.


Near Computer (which has its modem also not connected):

CurrentSet updated to E5EAFE5A-95F1-4FCF-BD6D-DBA940E01CC2 (Near 
Computer)

2006-07-15 07:47:40.890 EnTeP[2174] -[NetWatcher(NetWatcherPrivate) 
testUrll] can 1
2006-07-15 07:47:40.901 EnTeP[2174] -[NetWatcher(NetWatcherPrivate) 
testUrll] cu <NSURLConnection http://www.mdenkmann.de/>

2006-07-15 07:49:41.281 EnTeP[2174] -[NetWatcher(NetWatcherPrivate) 
connection:didFailWithError:] <NSURLConnection http://
www.mdenkmann.de/> NSError "no Internet connection" 
Domain=NSURLErrorDomain Code=-1009 UserInfo={
    NSErrorFailingURLKey = http://www.mdenkmann.de/;
    NSErrorFailingURLStringKey = "http://www.mdenkmann.de/";
    NSLocalizedDescription = "no Internet connection";
}

You might observe a delay of 2 minutes.

Kind regards,

Gerriet.

Related mailsAuthorDate
mlDetecting Internet Gerriet M. Denkman… Jul 14, 11:12
mlRe: Detecting Internet Jerry Krinock Jul 14, 15:25
mlRe: Detecting Internet Adam R. Maxwell Jul 14, 15:33
mlRe: Detecting Internet Gerriet M. Denkman… Jul 14, 23:06
mlRe: Detecting Internet Jerry Krinock Jul 15, 02:01
mlRe: Detecting Internet Gerriet M. Denkman… Jul 15, 07:57
mlRe: Detecting Internet Jerry Krinock Jul 15, 21:47