developing a Windows service equivalent in OSX

I am basically a Windows platform developer, and have developed a windows service that will run before the user login and keeps checking the public IP address of the running computer by creating and http connection to a website and reading the response in every 5 minutes. The service will send a mail through gmail smtp to a predefined email account whenever there is a change in the IP address. This IP-Watcher (I call it IP-Dog 🙂 ) is very useful as I am using remote desktop connection on an internet connection with a dynamic IP address.

I would like the expert opinion from all of you about what programming language, tools and IDE should I use to develop the same app on Mac platform that would

- autorun every time the Mac boots and stays hidden (preferably before user login)
- creates http connection with server and writes and reads simple textual data every 5 minutes.

I have experience in programming in all the .NET languages including VC++ and C#
I have also developed an iPhone application using the iPhone SDK 2.0/XCode and that was my first Mac experience.

Please enlighten me the possibilities and best choices.

IBM, Mac OS X (10.5.7)

Posted on Oct 5, 2009 8:53 PM

Reply
8 replies

Oct 6, 2009 12:44 AM in response to Vapssky

If you really want to learn to program on the Mac, you are going to want to learn C, followed by Objective-C. These are the two main languages that Mac programming is based around, although programming in C++, Java, and other languages is possible as well. I would recommend getting the book by Apress called Learn C on the Mac -- it is very helpful and will get you up and going with C in no time (if you already know other languages and have experience with programming in general, then this shouldn't be very hard). Especially since you said you have experience with Visual C# and Visual C++, learning C shouldn't be nearly as hard as it would be from scratch; however, it's important to keep in mind that there are very large gaps between a language like C# and actual C programming. C# takes a lot of "easy-way-outs" that you will likely have to find out about the hard way when learning C. But, it's worth it if you really want to learn programming on the Mac. After you get the basics of C down, that would be, in my opinion, a good time to move on to Objective-C. Objective-C is an object-oriented extension to C, so you shouldn't have to much trouble learning it, especially if you have experience with other object-oriented languages.

Now, that being said, if you simply have one application in mind that you want to develop on the Mac, and that's as far as your ambitions with Mac programming go, then there are other routes to consider. There are applications for Mac that are very similar to Microsoft's Visual Studio -- RealBasic and X-develop are the only two I have any experience with. It's worth noting that I don't recommend these apps for developing on the Mac, at all. I wouldn't even mention them, except that they hold a lot of similarities to Visual Studio, which you seem to have experience with, and, like I said, if you're simply trying to develop one app or so on the Mac and then call it quits -- they might be worth looking into, but they're not cheap if you want the full version.

Anyways, I hope you'll take the time to learn C and Objective-C. I think it's the better way to go. Please ask if you have any more questions.

Oct 6, 2009 1:59 AM in response to Vapssky

Vapssky wrote:
... a windows service that will run before the user login and keeps checking the public IP address of the running computer by creating and http connection to a website and reading the response in every 5 minutes.


That sounds very expensive in terms of CPU cycles and network load.

To do it the "Mac" way see "Technical Note TN1145" (Living in a Dynamic TCP/IP Environment). It shows you how to get the IP addresses of all interfaces as well as how to detect address changes. Do "Help -> Documentation" in Xcode and search for TN1145.

Also, do not forget to read up on launchd(8), the Mac equivalent (or is that badmouthing?) of Windows services. See the manuals "Guidelines for Creating and Launching Daemons" and "Creating launchd Daemons and Agents".


Regards,
Hans

Oct 6, 2009 7:25 AM in response to Vapssky

I think I am comfortable with any programming languages since I have had chanced to work with most of the programming languages ever since I started programming in 1988.

I was ok with learning the XCode/objective-C for iPhone and the application is already selling good on Apple Stores.

What I really want to know is

- Is it possible to use xcode and objectiveC to develop a daemon that does the above functionality ?
-or will I have to go for some other language ?
-which one is prefereable ?
-Where can I get a basic daemon application sample project on which I can write further code ?
-is it possible to get an http connection code sample ?

Please share your thoughts

Oct 6, 2009 7:42 AM in response to Vapssky

which one is prefereable ?


I really can't help you on this issue, since I don't really know anything about it, but I did want to clear one thing up. Above you asked "which one is preferable" -- I don't know what you are referring to here, but it sounded like you were asking which is preferable between Xcode and Objective-C. If that's what you were asking, then I think you should know that they are not two different options. They are two completely different entities -- one's a language and the other is an application. Objective-C is a language -- it is an extension to C, and a great deal of programming on the Mac is done using this language. Xcode, on the other hand, is simply the application that is used to write code on the Mac -- it is not a language at all. So neither one is preferable, because you will likely be using both. If you are programming in Objective-C, then you will have to use Xcode to do it. Xcode is nothing more than an application. I don't know anything about daemons, but I would assume C/Objective-C would be the language for something like this (but let someone else answer that part for you -- like I said, I don't know anything about this).

Oct 6, 2009 11:22 PM in response to Tron55555

Tron55555 wrote:


it sounded like you were asking which is preferable between Xcode and Objective-C).



Not the case.

As I have already mentioned that I have developed an iPhone application using iPHone SDK, which is only possible using XCode IDE and ObjectiveC language, there is no way that I am under the impressionj that both are different choices.

Can someone help me to make sure whether it is possible to develop the above app using XCode IDE and Objective C language, which seems to be the officially preffered solution for development from Apple.

Oct 7, 2009 12:22 AM in response to Vapssky

Is it possible to use xcode and objectiveC to develop a daemon that does the above functionality ?
-which one is prefereable ?


Not the case.
As I have already mentioned that I have developed an iPhone application using iPHone SDK, which is only possible using XCode IDE and ObjectiveC language, there is no way that I am under the impressionj that both are different choices.


Okay -- sorry about that. I just got that impression, and wanted to make sure. Anyways, I don't know if this will be helpful to you or not, but I did a little searching for this, and here's what I came up with:

Is it possible to use xcode and objectiveC to develop a daemon that does the above functionality ?
-or will I have to go for some other language ?


Well, like I've said before, I don't know enough about the specific functionality of the type of app you are building to say for sure what Xcode and Objective-C can or can not do in terms of that functionality. However, daemons can be built using Xcode, and you will want to use one of the Command-Line Utility templates to do it. If you want to write it in C, then choose the Standard Tool template, and if you want to write it in C/Objective-C, then choose the Foundation Tool template.

-which one is prefereable ?


still not sure what you mean by this

-Where can I get a basic daemon application sample project on which I can write further code ?


Someone asked a similar question that I found Googling -- don't know if it will be helpful to you or not, but wanted to throw it out there. Here's the link:

http://lists.apple.com/archives/xcode-users/2006/Jul/msg00132.html

They also give this link on the page above. I didn't find anything that seemed useful here, but maybe you can.

http://www.linuxprofilm.com/articles/linux-daemon-howto.html

-is it possible to get an http connection code sample ?


not able to be of any help here -- sorry.

Can someone help me to make sure whether it is possible to develop the above app using XCode IDE and Objective C language, which seems to be the officially preffered solution for development from Apple.


Again, let someone who is more versed in all this answer that question more exactly, but I would say the answer is most likely yes. I can't imagine that Xcode wouldn't be able to handle it.

Anyways, hope there was something useful in this. Best of luck with your project.

Oct 7, 2009 7:50 AM in response to Vapssky

Vapssky wrote:
- Is it possible to use xcode and objectiveC to develop a daemon that does the above functionality ?


Sure. There are some parts of Cocoa that are only used when there is a logged in user. I tried to find a definitive source for which parts those are, but I can't seem to locate it right now. Start here and you might have better luck.

-or will I have to go for some other language ?


You can use pretty much whatever you want. You can use Objective-C code with higher-level Cocoa or pure BSD code with C.

-which one is prefereable ?


It depends on what you are doing. If you need to access some of the MacOS X-specific data, you will have to use Cocoa or Carbon-ish code to access it. For other stuff you can stick to BSD. You can freely mix and match all of it together in the same project or file.

-Where can I get a basic daemon application sample project on which I can write further code ?


Here is a good technote on daemons.

I can't seem to find any examples really. There are there, I just don't have much time to look right now. Just remember that a launchd daemon is not like a Linux or other UNIX daemon. Linux daemons are supposed to do some funky things in the code. Launchd takes care of all/most of that. MacOS X daemons are easier to write than on Linux.

-is it possible to get an http connection code sample ?


There is tons of that for either Cocoa or BSD.

Oct 14, 2009 12:44 PM in response to Vapssky

Well, at least for what you want to do, i'm sure that there is a way in Objective-C.
Although I don't have too much experience with it, but regarding your goal of getting the ip. Why not just use a dynamic IP service, such as DynDns.org.

It installs a daemon that will update often with the current public IP. This is what I use to connect to my Mac remotely, or connect to my home computer's website, etc.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

developing a Windows service equivalent in OSX

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.