AJAX request in LAN (MSI Afterburner Remote Server)?

0 favourites
  • 12 posts
From the Asset Store
The official Scirra Multiplayer Signalling Server for helping peers find and connect to each other
  • Hi, I need your help.

    I try to make a small personal smartphone app, that shows me my pc stats like cpu load and such.

    I use MSI Afterburner and MSI Remote Server for this. The app is working so far in preview, but only in NWjs, in Chrome or on my smartphone with lan preview, the AJAX request fails. I think the problem is, that i dont have "Access-Control-Allow-Origin: *" in php header. But MSI Remote server has no php files.

    Has somebody an idea, how i can get this to work?

  • I'm not sure how MSI Remote Server works, but if it runs on Apache then you can use .htaccess file with the following content:

    <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    </IfModule> [/code:hcuh4vqk]
  • i placed the .htaccess file in the directory of msi remote server, but still nothing.

    Why does it work with nwjs but not with any other browser or on my smartphone?

    If i open the ip directly in browser, i'll get the xml output from the server, even on my phone, but not in construct.

    This is how the code looks like:

    i upload the .capx file, MSI Afterburner and the MSI Remote Server, if somebody likes to help me with my problem.

    .capx

    MSI Afterburner

    MSI Afterburner Remote Server

  • Is there any error message in the browser console when it fails?

  • chrome console gave me this, so you were right with your assumption:

    XMLHttpRequest cannot load http://192.168.0.50:82/mahm. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.0.50' is therefore not allowed access. The response had HTTP status code 401.[/code:35rntqyk]
    The question is, why is nwjs working and chrome not, and how do i grant construct access for the ajax call?
  • Hmm it could be that NW.js is treated as the same host (same IP) as the one you're trying to connect to, while Chrome preview starts it's own "server" and has it's own IP.

    I am not sure how NW.js preview is treated from this perspective. It could also be related to some Chromium args like "--disable-security" or something.

    And It's possible that AJAX works differently for NWjs. It may actually search for the file locally.

    Can you check what will something like this log to the console both in the Browser and NWjs?

    It's interresting that it works in NWjs. I'm curious what's behind it. Ashley is this maybe something you would know from the top of your head?

  • Most likely NW.js just disables security, which is probably not a great idea and sets up compatibility traps like this. You should configure the server correctly anyway. If you're not sure how to configure the server it would be best to contact support for MSI or whoever develops the server.

  • The question is, why is nwjs working and chrome not, and how do i grant construct access for the ajax call?

    This question is very similar to this topic. Grigrizljac gave me a very helpful answer, hope it helps you too.

    I try to make a small personal smartphone app

    However, if you plan to export to Android, it should work fine in the exported version.

  • The log in Chrome and NWjs prints the same output for Browser.URL and Browser.Domain:

    http://192.168.0.50/
    192.168.0.50[/code:3d8yhejn]
    
    @Ashley That are the remote server files:
    [img="http://i.imgur.com/3dqBoDp.jpg"]
    
    That is the config file in the app dir, it is primarily for setting up the the real config file in appdata:
    [code:3d8yhejn]<?xml version="1.0"?>
    <configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="MSIAfterburnerRemoteServer.Properties.MSIAfterburnerRemoteServer" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="MSIAfterburnerRemoteServer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <startup><supportedRuntime version="v2.0.50727"/><supportedRuntime version="v4.0"/></startup>
        <userSettings>
            <MSIAfterburnerRemoteServer.Properties.Settings>
                <setting name="Port" serializeAs="String">
                    <value>82</value>
                </setting>
                <setting name="IPAddress" serializeAs="String">
                    <value>*</value>
                </setting>
                <setting name="Key" serializeAs="String">
                    <value>17cc95b4017d496f82</value>
                </setting>
                <setting name="MonitorOnly" serializeAs="String">
                    <value>False</value>
                </setting>
                <setting name="NormalizeXMLResponse" serializeAs="String">
                    <value>True</value>
                </setting>
                <setting name="UseRealtimeOCValues" serializeAs="String">
                    <value>False</value>
                </setting>
            </MSIAfterburnerRemoteServer.Properties.Settings>
        </userSettings>
    </configuration>[/code:3d8yhejn]
    And that is the config of the remote server in appdata:
    [code:3d8yhejn]<?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <userSettings>
            <MSIAfterburnerRemoteServer.Properties.Settings>
                <setting name="Key" serializeAs="String">
                    <value>b3fe4ee9c3c91bd28ad1b8e144498764</value>
                </setting>
                <setting name="MonitorOnly" serializeAs="String">
                    <value>True</value>
                </setting>
                <setting name="NormalizeXMLResponse" serializeAs="String">
                    <value>True</value>
                </setting>
                <setting name="UseRealtimeOCValues" serializeAs="String">
                    <value>False</value>
                </setting>
            </MSIAfterburnerRemoteServer.Properties.Settings>
        </userSettings>
    </configuration>[/code:3d8yhejn]
    I see no possibility to configure the server  
    
    @ChesVCF Thanks for sharing the topic with me, it was exactly that. I disabled the the security in chrome with this command:
    [code:3d8yhejn]chrome.exe --disable-web-security --user-data-dir[/code:3d8yhejn]Now the AJAX request works.
    
    I will try to export my project and test it on my smartphone. I hope it will work than
  • You really, really should not go around turning off web security in Chrome. It opens up gigantic security holes. I would guess it enables any web page you visit to hijack your Facebook account or any other account you're signed in to, and that's just for starters. You should set up the correct HTTP headers. If you don't know how to, contact the server developer for support, or try a different web server that's easier to set up (both nginx and caddy seem pretty straightforward).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ashley I don't plan to disable Chromes security for the sake of my app. I only disabled it for testing. I even disabled all addons and closed all tabs beforehand. The app will only work in local network on a smartphone and is for now only for my personal use. Time will tell when and if i'll publish it.

    So don't worry, i'll do my homework

  • It's still better to set up the right HTTP headers. That is the correct solution!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)