Problem with glitch[Solved]


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

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

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

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

console.log ('Server started.');

playcanvas code

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

// initialize code called once per entity
Network.prototype.initialize = function() {
    this.socket = io.connect('');

// 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.


let me check


it is still not doing anything


The server code is unfortunately incorrect. The tutorial does have the full server code example at the bottom:

My example project:
And Glitch code:!/automatic-custard


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