How can I communicate with an IP on my LAN?


#1

I have a server running as a Docker container on my LAN. So the IP address, as is often the case with LAN devices, 192.168.0.x. My dev PC is also on this 192.168 IP address, which is where I’ve got PlayCanvas running in my Chrome browser.

I have some JavaScript which I’d like to send requests to my server. But when I do this, the request fails. I guess this is just because the host (playcanvas.com) cannot reach my Docker container on a LAN address.

How can I use a server on my LAN, with PlayCanvas?

Thanks.


#2

It should still reach it :thinking: as I assume you are making the connection on the client side.

If you pinged your Docker container from the commandline on your PC, does it find it?

Are you using the correct port number too?


#3

It would help if I typed in the right IP address! OK, I’ve corrected that, and now I get:

Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR

Here’s the code I’m using:

var NakamaTest = pc.createScript('nakamaTest');

// initialize code called once per entity
NakamaTest.prototype.initialize = function() {
    this.authenticate();
    console.info("this.authenticate() completed");
};

// update code called every frame
NakamaTest.prototype.update = function(dt) {
    
};

NakamaTest.prototype.authenticate = async function() {

    var client = new nakamajs.Client("WubbaLubbaDubDub", "10.1.200.12", 7350, true);

    console.log(client);


    const email = "hello@example.com";
    const password = "somesupersecretpassword";
    
    console.info("GOING TO AUTHENTICATE: " + email);

    const session = await client.authenticateEmail({
        email: email,
        password: password
    });

    console.info("Authenticated successfully.");
};

The console prints out “GOING TO AUTHENTICATE”, but never prints “Authenticated successfully”.
The last argument to nakamajs.Client() is true, which means ‘use SSL’. If I specify this as false, I get this error instead:
Mixed Content: The page at 'https://launch.playcanvas.com/777742?debug=true' was loaded over HTTPS, but requested an insecure resource 'http://10.1.200.12:7350/v2/account/authenticate/email?'. This request has been blocked; the content must be served over HTTPS.

Thanks.


#4

You can’t use non HTTPS URLs from a HTTPS source as it’s a security issue.

Either make your nakamajs server have a valid SSL and HTTPS connection or run the PlayCanvas app from HTTP which you should not do in production but is fine for development (ie http://launch.playcanvas.com/777742?debug=true)


#5

http:// worked perfectly - authentication works. Thank you @yaustar :slight_smile:

I will figure out the SSL stuff (that’s new to me) as soon as possible, as I will need to do that for production anyway. It’s not something I’ve got experience with, I am sure it will be easy :smiley: