views:

46

answers:

1

Anybody knows what changes are necessary for a server to work with xinetd ?

The server being a .NET mailserver that runs on Linux.

See the bottom of this post for reference: Lumisoft Mailserver Forum Post

Note: xinetd, not mono-service. [x]inetd is an internet superserver.
A superserver starts a server service on demand.
(As opposed to the server service running continuously, which is what mono-service does)

+2  A: 

An inetd service runs differently from a standalone server. inetd services read stdin and write to stdout, letting inetd handle the gory details of TCP/IP, rather than keeping track of their own sockets. If you want to make a server run under inetd, it'll have to do the same.

The following program runs just fine under xinetd on my machine:

#include <iostream>
#include <string>

using namespace std;  // yeah, i'm lazy.

int main()
{
    string name;
    cout << "What's your name? " << flush;
    cin >> name;
    cout << "Hi, " << name << "!" << endl;
}

Note i'm not at all worried about sockets -- xinetd arranges things so that the service can read standard input and write to standard output. You just write your app like you'd be running it on the console, for the most part. The socket details are specified in the config file for the service. (Note, you might be able to get/set details about the socket using stdin/stdout, which may be the actual socket -- i'm not sure -- but you really should leave that stuff up to inetd.)

cHao
Is there any sample, C++ or C or otherwise ?
Quandary
@Quandary: updated.
cHao
@cHao: Thanks, looks indeed very simple. There really is not more to it? So if a client connects to port whatever, he recieves "what is your name", sends his name, and gets back "Hi <name>". And I suppose the timeout is handled by xinetd. Very funny indeed. I think I have to take a look at xinetd programming, it makes a server look as simple as a single-client console program.
Quandary
@Quandary: Yep, it's that simple. There might be more advanced stuff you can do, i'm not sure. But you can pretty much just write the app as if you intend to run it at the console, and let xinetd take care of the TCP/IP stuff. It only gets complicated when you want two clients to be able to talk to each other, but that's not much different than console apps either. I'm not sure about timeouts, but you can do that within the program with signals without too much trouble.
cHao