not working?

When I try to use it does not work. It says this in the console:
When I go to that url it brings me to a screen that says this:
There must be something I am not doing right, because your example works.
Here is my code:

var Network = pc.createScript('network'); = null;
Network.socket = null;
// initialize code called once per entity
Network.prototype.initialize = function() {
var socket = io.connect("");
  Network.socket = socket;

Please help and thanks in advace!

Hi @HTML_Celeb,

That isn’t an error but a warning for missing the source map file for the library. That isn’t required to use the library, your code seems correct. Try sending/receiving a message to see if the connection is working.

1 Like

Also, I am confused.
This is how I did

  var socket = io();

and the server:

io.on('connection', (socket) => {


But you do it like this:

var socket = io.connect("");


io.sockets.on('connection', (socket) => {


They are different. Is the version in the tutorial (the one here: an old version?

Hi @HTML_Celeb, in case it helps, this is how I’m doing it on my project on both client and server side. It uses an HTTPS (and hence wss) connection, so it requires a little bit more configuration (credentials, cors):

/* Server side */
var cors = require('cors')
const express = require('express')()

var httpsServer = require('https').createServer(credentials, express)

// Server with CORS enabled and WS protocol for transport only
var wsServer = require('')(httpsServer, {
    cors: {
        origin: "*",
        methods: ["GET", "POST"]
    transports: ['websocket']

wsServer.sockets.on('connection', (socket) => {
    console.log("Client has connected!")
    socket.emit('customEvent', 'hello')


// Make sure your HTTP server is listening on the right port and address
httpsServer.listen(3000, '')

And then in the client side (make sure you’ve got your javascript file included in your PlayCanvas project so it can load properly):

/* Client side (e.g your network.js script) */
var socket = io.connect('wss://<your_server_endpoint>:3000', { transports: ['websocket'] });

socket.on('customEvent', function(data){
console.log(data) // should print 'hello'

Hope it helps.


It says credentials is not defined

Didn’t include that part as it should be your own credentials (private key, cert). For example:

const credentials = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')

where key.pem and cert.pem are your private key and certificate for the server, respectively. This tutorial is useful in case you need to know how to generate those:

1 Like

ahhh man :frowning: I have a really slow chromebook. Terminals wont work on chrome os, I am sorry :frowning:

I think you should update that tutorial. It only works in version 2.0.4 of

but how do you do it on