Problem with glitch

I’m trying to communicate with the glitch server but i seem to keep getting the same error(I properly installed socket.io onto the server)

glitch error: TypeError: Cannot read property ‘on’ of undefined
glitch code

var server = require('http').createServer();
var io = require('socket.io')(server);

io.sockets.on('connection', function(socket) {
    console.log("Client has connected!");
});
io.socket.on ('playerJoined', function (name) {
           ^
         (error)
    console.log (name);
});

console.log ('Server started.');
server.listen(3000); 

playcanvas code

var Network = pc.createScript('Network');

// initialize code called once per entity
Network.prototype.initialize = function() {
    this.socket = io.connect('https://gun-game-server.glitch.me');
  
};

// update code called every frame
Network.prototype.update = function(dt) {
    this.socket.emit ('playerJoined', 'John');
};

Shouldn’t it be io.sockets.on? (note the extra s).

O_O Internal screaming
Im mad at myself

I now can’t seem to get glitch to revive info from play canvas using emit

Do you mean ‘can’t’?

(i type too fast) yes i mean can’t. can you help?

Haven’t used sockets but it looks odd to emit every frame.

The tutorial project here does it once in the init function. https://developer.playcanvas.com/en/tutorials/real-time-multiplayer/

let me check
:slight_smile:

it is still not doing anything

The server code is unfortunately incorrect. The tutorial does have the full server code example at the bottom: https://developer.playcanvas.com/en/tutorials/real-time-multiplayer/

My example project: https://playcanvas.com/project/590282/overview/socketio-test
And Glitch code: https://glitch.com/edit/#!/automatic-custard

i also figured it out. i had it outside of the io.sockets.on()function

Hi everyone, i came across this post since can’t connect from playcanvas to glitch.

Playcanvas, socket never getnnected to glitch, hence all the rest is not working, does anybody has success on it, or running the original tutorial project ?

Thank you very much