Hi, I’m just testing Glitch (which seems really great).
Like many, I’m starting with a small game based on Node.js, Express which uses socket.io for multiplayer features.
It’s a kind of distributed pacman very simplified (without walls and ghosts!)
As always, it works well on my LAN but I have some problems to make it work on glitch on the communication part between the client (web browser) and the node.js server
On the server side (server.js), here is how I initialize the listening socket:
var express = require("express");
var app = express();
var server = app.listen(process.env.PORT || 3000, "0.0.0.0", listen);
function listen() {
var host = server.address().address;
var port = server.address().port;
console.log("Example app listening at http://" + host + ":" + port);
}
app.use(express.static("public"));
On the client side , the code that runs on the client browser (/public/sketch.js) here is how I connect to the server:
socket = io.connect("https://gamemanu.glitch.me:3000/");
From the point of view of the deployment and configuration files, I have this:
{
"name": "simple io sockets p5",
"version": "1.0.0",
"description": "This is an example for how to use sockets with node.js and express and socket.io",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"author": "num_gg from Daniel Shiffman's courses",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"socket.io": "^4.2.0"
}
}
On the logs, my server seems to be correctly listening on port 3000 (the listening message is displayed correctly) but nobody is connecting.
On the browser, the js app loads but doesn’t communicate on the socket at all. It sends nothing and receives nothing.
What am I missing to make it work?
Here’s the glitch project url: https://glitch.com/edit/#!/gamemanu