Unable to establish a remote connection to the dlib webserver, but local host connection is functioning

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.

Answer №1

In order to avoid overwhelming the server and depleting its memory, dlib's web server enforces a restriction on the size of HTTP headers and query path strings. Each must be under 16KB in length individually, and if a client attempts to exceed this limit, they will receive an error message stating "http field from client is too long."

It appears that you may be generating an excessively long path or sending back a very large header (potentially due to a large cookie being created). You can modify the 16KB limit by editing line 129 in dlib/server/server_http.cpp. I plan to implement a feature allowing this to be set through a member function in the upcoming release.

However, it is unusual to reach the 16KB limit considering the typical lengths of path strings and HTTP headers. There could be another issue at play within your HTTP client code causing this limitation to be triggered.

Answer №2

It seems I have finally cracked the code. It turns out that my router lacks a feature called NAT loopback. This explains why my web server can be accessed remotely but not from within the LAN network.

The information source is in German:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sharing application state between different routes in React Router v4 can be achieved by using methods such

I'm seeking solutions to address the following challenge: Without utilizing any state management library, I solely rely on React. The primary application state is contained within the <MyFoodApp/> component, which includes an array of restaura ...

Why is it not performing as expected when removing all non-numeric elements from the array?

let arr = [1, "5", 3, 27, undefined, { name: 'Steven' }, 11]; for (let i = 0; i < arr.length; i++) { if (typeof arr[i] !== 'number') { arr.splice(i, 1); } } console.log(arr); // result: [1, 3, 27, {…}, 11 ...

Error: Google Chrome Extension must be used on the Dev Channel or a newer version

I am currently working on developing a Chrome extension for creating URL shortcuts. However, upon trying to add it to the browser, I encountered the following error: There were warnings during the installation of this extension: * 'app.lin ...

My goal is to dynamically assign a class to an iframe element by identifying a specific class contained within the html of the iframe

I need assistance with adding a class to an iframe only if the body tag has a specific class name. Here is my attempt at writing some code: <iframe class='iframeContent' src='' width='100%' height='' frameborder= ...

Dynamic jQuery Carousel

Is there a jQuery slider that can adapt to different screen sizes and handle images of varying widths? Appreciate any insights! ...

Error: Unable to load L.GeometryField constructor in django-leaflet library

I'm having trouble saving a geolocation to a Postgres database using Django-leaflet. I keep getting an error message that says Uncaught TypeError: L.GeometryField is not a constructor. My code involves AJAX calls. <script> var csrftoke ...

Managing multiple checkbox selections in React.js

Hello everyone, I'm currently working on trying to assign a function to my "select all" checkbox button to toggle the state when the button is clicked. However, I seem to be encountering an issue. Can anyone lend a hand? Here is my current state: ...

issue with mark.js scrolling to selected sections

Our document searching functionality utilizes mark.js to highlight text and navigate to the results. You can see an example of this in action here. If you search for "Lorem ipsum" -> the highlighting works perfectly, but the navigation jumps to fragmen ...

Utilize Angular's ng-repeat directive to iterate through this JSON data structure for implementing user-to

Struggling with the user-to-user messaging interface on an app and having difficulty using ng-repeat on the items. Here is the provided data: { "ID": 4118, "CreatedDate": "2015-08-20T03:12:50.397", "recipient": [ { ...

Showcasing information from a database on an HTML page with the use of Node

I am currently attempting to fetch data from my database and display it on an HTML page in a table using EJS for rendering. I found inspiration for my code on this website: Although the database connection is successful, I am encountering difficulties wit ...

My asp.net MODAL is not showing the data, what could be the issue?

I'm facing an issue where I can't display a gridview inside an ajax modal. Everything else displays fine except the gridview. Oddly enough, when I tried displaying the gridview outside the modal, it worked perfectly. What could be causing this in ...

Obtaining the ID of a moved item in Uikit's nestable component

I am currently utilizing the uikit framework and have a query regarding the nestable component. Despite seeking assistance in various places, none of the solutions seem to match my specific needs. My limited knowledge of JavaScript may be a contributing ...

Utilizing WinGDI to Rotate HDC

This post contains a lot of code, but the first block is just for reference to show the initial function. I am currently attempting to rotate hdcText by either -270 or 90 degrees in the code below: void CImageWindow::Show() { // C ...

Even though I am attempting to submit a form without refreshing the page using Ajax, it is still causing

I've searched high and low, read through numerous examples on various forums, and attempted to find the solution to my query but unfortunately, it still eludes me. Here's the particular scenario I'm facing: Main.php The main.php page featu ...

Implementing a parallax scroll effect using CSS and dynamically updating the background-position value with JavaScript

How can different Y position percentages be dynamically assigned to multiple layered background images in CSS using JavaScript so that they update as the page scrolls? <style> body { background-image: url(img/bg-pattern-01.png), ur ...

Ways to resolve the error message 'ReferenceError: matrixo is not defined'

I am facing an issue where my program cannot find the matrixo function that is supposed to be in the random.js file, but it's actually located in server.js. Where should I require the random.js file to fix this problem? server.js var matrix = matri ...

Setting the x-api-key header with HttpInterceptor in Angular 4: A guide

I am attempting to use HttpInterceptor to set the header key and value, but I am encountering the following error: Failed to load https://example.com/api/agency: Response to preflight request doesn't pass access control check: No 'Access ...

I am looking for a way to add multiple checkboxes using PHP-jQuery in conjunction with MSSQL Server. Can

I am encountering an issue while attempting to save multiple checkbox values into an MSSQL server database using PHP and jQuery. Upon executing the code, I encounter the following error: The problem seems to lie within the PHP code. How can I parse this ...

Tips for displaying a table with a button click

I am struggling to figure out how to embed a table inside a button in order to display the table when the button is clicked and hide it when clicked again. Below is the code I have been working with: function toggleTable(){ document.getElementById ...

Tips for preserving line breaks when sending a message through the mail

Hi, I'm currently facing an issue: I am trying to send text from a textarea using POST to a PHP script that will write it to a file and display it on the website. However, when I do this, the line breaks disappear and the displayed text ends up lookin ...