Easy Servers on OS X
Using xinetd to Make Painless Servers in REALbasic
Issue: 3.1 (September/October 2004)
Author: Brady Duga
Author Bio: Brady Duga has been a professional programmer for over a decade. He has been using REALbasic at every opportunity for the last several years. When he is not at his day job or spending time with his family, he can be found writing freeware and shareware for the La Jolla Underground.
Article Description: No description available.
Article Length (in bytes): 20,743
Starting Page Number: 21
Article Number: 3110
3110.zip Updated: 2013-03-11 19:07:58
Related Web Link(s):
Excerpt of article text...
In our increasingly connected computing world, it is only a matter of time until you will have a need for a custom server application. This could be anything from a simple CGI script for a web server to the web server itself. In the former case, the web server handles most of the work for you, establishing connections, authenticating users, and balancing server load, among others tasks. At the other end of the spectrum is writing a high-performance, scalable server that handles asynchronous, secure, threaded connections. Of course, there are numerous simple servers that are not suitable to be implemented through a web server. Does that mean you have to jump directly to the difficult task of writing a server from scratch?
Not if you are running a current version of Mac OS X (10.3 or higher) and have a copy of REALbasic (Professional version 5.5.1 or higher). Using software available to UNIX programmers for years and the new Mach-O console applications of REALbasic, it is possible to write a server without knowing a thing about sockets, server or otherwise. The key to this lies with the extended internet services daemon (xinetd) super-server. Once upon a time, in the deep, dark history of the computing world (ten years ago), an internet "super-server" was created called inetd. Sometime during the 'nix renaissance, an extended version, xinetd, was crafted by BSD monks and it is this version that is currently used by Mac OS X. What is its nefarious purpose? Originally, inetd listened for connections on various ports of your computer. When an incoming connection was detected, the network stream was passed off to a smaller console application that actually handled the data. Xinetd does this, plus a lot more, like preventing some types of Denial of Service attacks and performing extensive logging.
Now, I see you are scratching your head, wondering what in the world this has to do with REALbasic. Remember that comment about console applications? Well, those can now be created with REALbasic 5.5. I suppose you are wondering how that might help us. Won't we still need to learn about sockets and such to handle these network connections, not to mention threading, so we don't hog the CPU? No, I say! This is where that "easy" part comes in. The console application simply reads from standard input (stdin) and writes to the standard output (stdout), which are easily accessed with the "print" and "input" methods, or using the "stdin" and "stdout" classes. This makes writing a simple, procedural server a trivial task. You just keep reading data and responding to it until you decide your work is complete. We will now embark on the creation of our simple server. This server will be an (extremely) trivial http server, responding to the most basic 'GET' requests. We will also walk through the steps required to configure xinetd to run your server as well as addressing any special considerations required for running a REALbasic application under a super-server. All this will be done with a handful of lines of code, with no sockets and no threads.
...End of Excerpt. Please purchase the magazine to read the full article.