How to write a server ?

Extracted from askslashdot
Tip provided by ?
Allen Rouse asks " What books are there that deal exclusively with the issues of writing servers? For example, Richard Stevens' books deal with the tools needed to write any kind of UNIX software, servers are just one among many. He mentions general TYPES of servers but not much about the specific issues encountered in writing complex servers (like say NetTrek or an ORB)."

Stallman is the starting point
Specifically, the book series
"Unix Network Programming" is a very very good place to start. Currently, only the 1st volume of the series is available, but it is offers a very in depth view of what to do to write a server (and clients, etc) and why. Unfortunately, Stallman has a nasty tendancy to make you read through his entire book to understand a more advanced concept, so you can't just 'flip' to a later topic and pick up there without at least some going back of chapters to see how he explains things... even if you already have an idea of what he's trying to say.

If you're like me, you probably want to immediately leap into an operational code situation right away. There's a number of FAQs online about quick 'n dirty client server, but a suprisingly straightfoward c-s demonstration is available in the Perl manual, by typing man perlipc. That's where I got my start.

Hmm... well, it depends on what you want to serve. And how you want to transmit information. You can write "server" shell scripts, and run them from inetd, and they will use their standard in/standard out. A simple web "server", for instance, could be

HTTP/1.0 200 OK
echo Content-type text/html
echo '<html><head><title>Hello!</title></head><body>Hello, World! You said:'"`cat`"'</body></html>'

run from port 80.

Now, if you want a daemon, I don't remember... you have to fork, cut off stdin/out/err, and do a couple of other things...

Also, remember that this server should be secure. Keep away from possible buffer overruns. Stuff like that.

Secure programming hints
For servers, it's important to start thinking in terms of security as early as possible.

Here are some nice resources I've found that deal with secure programming:

Follow-up :
| Previous | Next | Index of category | Main Index | Submit |

Appears in section(s) : net programming
Tip recorded : 02-11-1998 10:00:00
HTML page last changed : 27-07-1999 20:08:02