Connection refused with DigitalOcean droplet on HTML

Hey, I’m new around here. :wave:

I’m using Defold to create a test game using Nakama as a backend for a real-time client authoritative game. Everything works as it should when testing locally within the Defold IDE, but when bundled to HTML5 I get this error:

WebSocket connection to 'ws://142.93.41.41/ws?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiI2OWI2ZGMxMC0zODE3LTQ3ZTItOWFlMS1kYTkzODJiZjY2NjQiLCJ1c24iOiJudkdCVHVKdWpsIiwiZXhwIjoxNjE0NzY4MzIzfQ.tSGf0HKb59dMgYjIHF7GnVPrjmB3vadXN3SaDIEbles' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I’m running the Nakama instance from a DigitalOcean Nakama droplet. I’ve changed the config file Nakama uses to be ready for production, but that doesn’t seem to make any difference. Are there additional steps to configure a websocket connection when the client connects from a web browser?

@totebo Hi there! Looks like the connection is being refused, and ERR_CONNECTION_REFUSED usually means there wasn’t even a server on the other end accepting traffic on that port so the target machine refused it completely.

This usually happens when you’re trying to use the wrong port. You’re trying to establish a WebSocket connection on port 80, are you sure this is correct? The server by default listens on 7350 so unless you’ve changed that in the server config you should update your connection settings in the client.

Hi, thanks for the response! I’ve configured Defold to port 7350 and there are no errors when connecting from Defold IDE.

Looking at the error you’re right - the port is missing from the call, so it probably defaults to 80, which is not configured to accept connections.

I’ll do some more digging tomorrow. Cheers!

Update: Changing the Nakama server and client to run on port 80 fixes the issue. My best guess is that the Defold websocket/Nakama integration for some reason defaults to port 80 even though a different port is specified in the Defold config. I’ve also posted this on the Defold forums.

A final update on this: The Defold Websocket extension has been updated which now allows any port to be used on HTML. :partying_face:

2 Likes