我在后台运行server.cpp
client.cpp
将连接到服务器并执行其任务。
我将服务器编码为侦听连接while(1)
,并为客户端分叉进程。
但是我有一个提醒功能,需要在特定时间给客户发送电子邮件。如何在此服务器,客户端cpp文件中一起运行该功能?它应该在服务器或客户端文件中运行,以什么方式运行?我曾尝试在client.cpp上fork(),但问题是它导致我的客户端无法正常工作。
我应该在哪里添加此代码,以及如何在执行server.cpp
时的连接时使其工作?
答案 0 :(得分:1)
在服务器代码中:
while(1) {
check for update time and
fork updater if needed
listen for clients
fork client
}
或者,服务器可以使用以下代码创建单独的线程:
while (1) {
sleep for some time
update customers
}