• Hi, Pleskians! We are running a UX testing of our upcoming product intended for server management and monitoring.
    We would like to invite you to have a call with us and have some fun checking our prototype. The agenda is pretty simple - we bring new design and some scenarios that you need to walk through and succeed. We will be watching and taking insights for further development of the design.
    If you would like to participate, please use this link to book a meeting. We will sent the link to the clickable prototype at the meeting.
  • (Plesk for Windows):
    MySQL Connector/ODBC 3.51, 5.1, and 5.3 are no longer shipped with Plesk because they have reached end of life. MariaDB Connector/ODBC 64-bit 3.2.4 is now used instead.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.

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