Currently, I am in the process of building a front end using HTML and JavaScript with a C++ backend to handle all calculations. The two are connected through an integrated dlib web server that manages requests. When the frontend requests data, it looks like this:
pop=$.ajax({ //load Population array of 90
type:"POST",
url: "Pop90",
async:false
});
eval(pop.responseText);
The web server then sends back a large array (around 4,000,000 entries) as a single string. Everything works fine when I'm testing locally, but I can't access the server remotely from another computer. The browser keeps loading for a while and then times out, even though I can see the requests on the server side. The server throws an error: dlib.server_http: http field from client is too long. However, I believe the size of the actual POST request from the client should not be the issue; rather, it may be related to the response size. Thank you in advance for any help! To provide more details, I ran tests on the page in Firefox, which also fails to load when accessed locally. The error console indicates an issue with the array initializer, which is the response string from the web server and appears something like this (but much longer with millions of entries):
"ar=[-99999, -99999, ...]"
The web server class responsible for handling requests is structured as follows:
class web_server : public server_http
{
vector<vector<double>> pop90;
vector<vector<double>> pop95;
vector<vector<double>> pop00;
public: web_server::web_server()
{
cout<<"init...";
loadArray("data/raw/afp90g.asc", &pop90);
cout<<" 90 loaded...";
loadArray("data/raw/afp95g.asc", &pop95);
cout<<" 95 loaded...";
loadArray("data/raw/afp00g.asc", &pop00);
cout<<" 00 loaded...";
cout<<"ready!"<<endl;
}
const std::string on_request (const incoming_things& incoming, outgoing_things& outgoing)
{
cout<<"---------------------------"<<endl;
cout<<incoming.path<<endl;
ostringstream sout;
sout<<get_file_contents("Seite.html");
cout<<"content type: "<<incoming.content_type<<endl;
cout<<"request type: "<<incoming.request_type<<endl;
string filename=incoming.path.substr(1,incoming.path.length());
if (incoming.path.substr(0,1) == "/" && incoming.path.length()>1)
{
if (incoming.path=="/css/Style.css") outgoing.headers["Content-Type"] == "text/css";
if (incoming.path.substr(0,8)=="/Pop90") return parseArray(pop90);
if (incoming.path.substr(0,8)=="/Pop95") return parseArray(pop95);
if (incoming.path.substr(0,8)=="/Pop00") return parseArray(pop00);
return get_file_contents(filename.c_str());
}
return sout.str();
}
};
I made some adjustments to the server_http.cpp file to capture the full stream of incoming data. Interestingly, when connected locally, there seem to be random -1 values (EOF) interspersed between valid HTTP messages. However, when connecting remotely via my IP address, only -1 values are received consistently. I have disabled firewall/antivirus software and ensured proper port forwarding, but I am still unable to identify the root of the problem.