2
votes

Started following a tutorial for networking for my unity game (not done this before).

It's so far created some really simple script which can be connected to. Here's what I have:

var io = require("socket.io")(process.env.port || 3000);

console.log("Server Started");

io.on("connection", function (socket) {
    console.log("Client Connected");
});

In Unity, I have a gameobject with a Socket IO Component (from an asset on the store) on it. From CMD, I run the local version of server.js (code above), and see "Server Started" appear. In Unity, the GameObject has its URL set to: ws://127.0.0.1:3000/socket.io/?EIO=4&transport=websocket, and when I play unity, it connects. This is shown with "Client Connected" appearing in the cmd window.

The tutorial doesn't go into how you might deploy anything like this, so I was just making sure it was going to definitely work before I continue.

I created a digital ocean droplet, with Node.js on. I navigated to srv/www, and installed express as well as socket.io, like I did locally. I uploaded (via ftp) server.js to the location, and ran it. I saw the "Server Started" appear. When I change the IP address in the URL in unity, maintaining the port and everything after it etc, and press play, it doesn't appear to connect. I never see any "Client Connected" message.

It feels like the final hurdle, but I can't work around it.

Have I put things in the wrong directory? What am I doing wrong, why is it not connecting?

1

1 Answers

0
votes

Figured it out. I hadn't opened the port, so the connection wasn't getting through because of that. "sudo ufw allow 3000" was what I needed. :)