我试图使用 Qt 来创建一个在 Linux 操作系统上与 Inetd/xinetd 一起工作的服务器/客户端程序。
我已使用此文本将服务配置文件添加到 /etc/xinetd.d/testServ
service testServ
{
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/sbin/testServer
}
然后我将此行添加到 /etc/services
testServ 5050/tcp # the service uses the port nr 5050 and tcp protocol
我创建了一个特殊的客户端程序,它使用指定的端口连接到服务器,它可以正常工作。
问题出在服务器程序上。我在服务器程序的主函数中写了这段代码
Int main(int argc, char *argv[]) {
qDebug()<<"starting the daemon version of server client app";
QApplication app(argc, argv);
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stdin, NULL, _IONBF, 0);
QFile fstdin;
QFile fstdout;
fstdout.open(stdout, QFile::WriteOnly|QFile::Unbuffered);
fstdin.open(stdin, QFile::ReadOnly);
CleintProcess clientproc (NULL, &slog, argc, argv, &fstdin, &fstdout);
app.exec();
return 0;
}
服务器程序的问题在main函数的第二行,在这行之后程序没有继续。如果我在此行之后打印某些内容,它不会出现在屏幕上,但如果我在此行之前打印某些内容,则会出现打印消息。我不知道为什么 Inetd/xinetd 不能与 QApplication app(argc, argv);
当我删除这一行和另一行(app.exe)时,程序直接终止。
我需要 QApplication,因为我在对象 clientproc( ....) 中多次使用它。
你能帮我解决这个问题并让 qt 在 linux 上与 inetd/xinetd 一起工作吗?