Internet Check

Hi there!

Me got a problem, so, I’d like to check if there is an internet connection in an idle handler (repeat/return 30), now I’ve tried everything, from the “(get ((“http://www.yahoo.com/” as URL)'s host & {dotted decimal form:”“})'s dotted decimal form)”, through “With timeout” handlers etc. it all works ok until the actual Modem is down. This is trouble, because the app hangs, Internet Connect shows a valid connection, and therefore the event tries instead of spiting an invalid connection. I’ve also tried with pinging, but it’s always the same thing, it hangs. I’ve tried sending the request to another app, like “System Event” with a timeout of 2, my app is fine, but then “System Event” is hanging…

It’s just silly, and btw it’s all Apple come up with, ever tried connecting to the router, unplugging the line and opening your iDisk (if you’ve got one), hanging hanging. I wish there would be a simple and effective way to check the connection…

Any brilliant idea anyone?

Micha

Have you tried something like this?


try
	do shell script "curl 'http://www.yahoo.com'"
	set theinternet to true
on error
	set theinternet to false
end try

Schlaeps,

thanks for your response, but I had tried that, the app would hang at least for 7 seconds, if you’ve got it in a idle/repeat/return 60, it doesn’t work… again, connected to a router but the router missing the internet connection. Does Applescript handle Multi Threading?

Micha

You’re probably going to encounter a hang no matter what you do as long as your call is in your app’s main thread. The problem is that when your app issues the command (whetever it is) it sends it and then waits for a response from whoever you’ve issued the call to. Ultimately, the call is handed to the system where is gets hung up. The only way you’re going to get this fixed is likely going to be to create another thread somewhere, somehow. Which leads us to…

Short answer… NO. Since applescript studio is really just a front-end for the underlying cocoa methods, you can fairly easily write a subclass that will handle a second thread, but if you knew how to handle secondary threads you’d have already known that and implemented it, most likely. And, if you could do that, you’d probably be writing your whole app in obj-c. I’ve commented on multiple threading in studio in this thread recently, and it’s something you’ll have to keep messing with to find an acceptable solution to.

Putting ‘repeats’ in an idle handler is a bit redundant for testing your connection. “Idle” handlers essentially are timed repeats. If you’re repeatedly testing for your connection in your idle handler in a repeat loop, you’re probably misusing the repeat command in this case. It would be better to return a smaller interval and test only once. Perhaps I’m misunderstanding what you’re doing?

Basically, you’ll have to find a way to put your call on another thread… either by using some creative hack or by actually creating a separate thread in custom obj-c code. The disadvantage to actually creating a separate nsthread is that it’s difficult to manage secondary threads and to communicate between obj-c and applescript. If you can resolve those issues, that may be an acceptable solution, but it may be a lot of work for what you’re trying to accomplish.

The other option, is to find a graceful way to handle the lag. If the test for the connection is an integral part of your app, then the user might need to be aware that it’s happening and you should pop up a panel or progress indicator to show that it’s being tested. This sounds ugly, but if you’re going to develop an app in studio, you’ve go to accept that the resources available to you are limited in some ways. If you want to add features that aren’t built in, then it’s up to you to invent them. It sounds like you’ve exhausted most of the options I would recommend, so you may have found the list of solutions that you’re going to have to choose from. :frowning:

Sorry I can’t be of more help right now. If I didn’t already have so much going, I might be able to look into it a bit more offer better advice. Good luck,
j

Jobu,

I very much appreciate the time you’ve taken to respond. I also value your response. It looks like I’l have to jump into ObjC… All good for my neurons, but not so good for my free time.

Micha