Re: Detecting Internet
Re: Detecting Internet
- Subject: Re: Detecting Internet
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Sat, 15 Jul 2006 07:57:33 +0200
On 15.07.2006, at 03:34, email@hidden wrote:
Subject: Re: Detecting Internet
To: Cocoa Developers <email@hidden>
Message-ID: <C0DD7E5D.23E96%email@hidden>
Content-Type: text/plain; charset="US-ASCII"
on 06/07/14 14:06, Gerriet M. Denkmann at email@hidden wrote:
On 14.07.2006, at 17:49, Jerry Krinock <email@hidden> 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.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden