• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Issue Cant get my WebSocket running in NodeJS on Plesk Server?

Chris Christou

New Pleskian
I am trying to deploy a little collaborative drawing app using Node.js, Express.js and Socket.IO.

Locally it runs perfectly on MacOS running Node.js, over both LAN and WAN, but I can't get it running on our Plesk server. I’ve followed Alexei Yuzhakov’s guide to install and configure Node.js in Plesk:

How to Work with Node.js Apps on Plesk Obsidian

I also used some of the Node.js test apps and everything seems to be configured and working.

I’ve then installed my app and run the NPM install to download the dependencies successfully.

However when clients try to connect they get the following error:

Failed to load resource: The request timed out. http://example.com:3000/socket.io/?EIO=3&transport=polling&t=NWEYhCy

Somehow the clients are unable to connect to the socket on port 3000

Ive tried various things like disabling PHP and I've also removed the proxy-mode setting checkbox in the Apache settings. But no luck.

Any help would be appreciated!

Server Code (server.js):

Code:
// Using express: http://expressjs.com/
var express = require('express');
// Create the app
var app = express();

// Set up the server
var server = app.listen(3000, listen);

// This call back just tells us that the server has started
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'));


// WebSocket Portion
// WebSockets work with the HTTP server
var io = require('socket.io')(server);

// Register a callback function to run when we have an individual connection
// This is run for each individual user that connects
io.sockets.on('connection',
  // We are given a websocket object in our function
  function (socket) {
 
    console.log("We have a new client: " + socket.id);
 
    // When this user emits, client side: socket.emit('otherevent',some data);
    socket.on('mouse',
      function(data) {
        // Data comes in as whatever was sent, including objects
        console.log("Received: 'mouse' " + data.x + " " + data.y);
    
        // Send it to all other clients
        socket.broadcast.emit('mouse', data);
      
        // This is a way to send to everyone including sender
        // io.sockets.emit('message', "this goes to everyone");

      }
    );
  
    socket.on('disconnect', function() {
      console.log("Client has disconnected");
    });
  }
);

Client Code:

Code:
// Keep track of our socket connection
var socket;

function setup() {
  createCanvas(window.innerWidth, window.innerHeight);
  background(250,250,250);
  // Start a socket connection to the server
  // Some day we would run this server somewhere else
  socket = io.connect('http://example.com:3000');
  // We make a named event called 'mouse' and write an
  // anonymous callback function
  socket.on('mouse',
    // When we receive data
    function(data) {
      console.log("Got: " + data.x + " " + data.y);
      // Draw a grey circle
      fill(100,100,100);
      noStroke();
      ellipse(data.x, data.y, 5, 5);
    }
  );
}

function draw() {
  // Nothing
}

function mouseDragged() {
  // Draw some grey circles
  fill(100,100,100);
  noStroke();
  ellipse(mouseX,mouseY,5,5);
  // Send the mouse coordinates
  sendmouse(mouseX,mouseY);
}

// Function for sending to the socket
function sendmouse(xpos, ypos) {
  // We are sending!
  console.log("sendmouse: " + xpos + " " + ypos);
 
  // Make a little object with  and y
  var data = {
    x: xpos,
    y: ypos
  };

  // Send that object to the socket
  socket.emit('mouse',data);
}
 
Back
Top