我有一个个人服务器,我想向其中添加一些新功能。它是一台运行Windows Server 2019的Windows服务器。核心程序是我用c ++编写的,但它只是一个核心,无法访问互联网,它应该从网页中接收一个字符串并返回一个字符串。我的旧方法是使用ASP创建一个文件来存储网页中的字符串并使用我的c ++程序覆盖它,但是如果服务器同时执行两个任务时间,结果将变成一团糟。我的ISP阻止了端口80,所以我使用端口8012来运行我的网站。我的路由器无法映射到外部的许多端口(服务器中还有FTP服务和邮件服务。 ),所以我只能使用端口8012,应该怎么办?我应该编写C ++ HTTP服务器吗?服务器信息:
服务端口内端口外端口软件
WEB 80 8012 IIS
FTP 21 21 Serv-U
FTP-pasv 6000-6009 6000-6009 Serv-U
POP3 110 9110
SMTP 25 9025
RemoteDesktop 3389 3389 Windows
我已经解决了我的问题。我正在使用一些AJAX代码添加时间符号和随机数,以避免请求崩溃。这是AJAX代码:
function GetValue(id)
{
return document.getElementById(id).value;
}
function SetValue(id,val)
{
document.getElementById(id).value=val;
return;
}
function GetTRValue() //Time-Random value,avoid messing up request
{
var rdm=Math.Random().toString(16);
var dt=new Date();
var time=dt.getTime().toString(10);
var tr=rdm+time;
return tr;
}
function EncodeRequest()
{
var req=new XMLHttpRequest();
req.onreadystatechange=function(){
if(req.readyState==4 && req.status==200)
{
SetValue('code',req.responseText);
}
else if(req.readyState==4 && req.status!=200)
{
alert('Server error:'+req.status);
}
}
req.open('POST','/base/base.asp',true);
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
req.send('type=encode&code='+GetValue('base')+'&srcstr='+GetValue('str')+'&rdm='+GetTRValue());
return;
}
function DecodeRequest()
{
var qer=new XMLHttpRequest();
qer.onreadystatechange=function(){
if(qer.readyState==4 && qer.status==200)
{
SetValue('str',qer.responseText);
}
else if(qer.readyState==4 && qer.status!=200)
{
alert('Server error:'+qer.status);
}
}
qer.open('POST','/base/base.asp',true);
qer.setRequestHeader('Content-type','application/x-www-form-urlencoded');
qer.send('type=decode&code='+GetValue('base')+'&srcstr='+GetValue('code')+'&rdm='+GetTRValue());
return;
}
在我的ASP文件中,我只创建了一个名为“时间随机值”的文件夹,并将请求文件放在此处。然后等待C ++程序的响应,将其读取并删除该文件夹。在我的C ++程序中,我扫描文件夹并将响应写入同一文件夹。