I'm trying to get my nodejs socket.io app work in my site with no results. On my own computer it works fine with xampp.
npm install --save express@4.10.2
and npm install --save socket.io
are installed
Here's my code: server.js that I run with nodejs
var socket = require( 'socket.io' );
var express = require( 'express' );
var http = require( 'http' );
var app = express();
var server = http.createServer( app );
var port = 8080;
var io = socket.listen( server );
io.sockets.on( 'connection', function( client ) {
console.log("New user connected");
client.on('message', function( data ) {
console.log( 'Message: ' + data);
io.sockets.emit( 'message', data);
});
});
server.listen(port, function(){
console.log("Listening on port: " + port);
});
Here's my index.php
<script src="script/node_modules/socket.io-client/dist/socket.io.js"></script>
<script>
var socket = io.connect( 'http://localhost:8080' );
</script>
I'm doing this differently than this because I'm using apache.
I'm getting this error no matter is the server.js
running with nodejs or not I always get this same error.
Virtual machine is from digitalocean.
All ports was blocked but 22, 80 and 443.
I allowed port 8080 with sudo ufw allow 8080
and sudo ufw allow out 8080
but it didn't work.
ufw was disabled sudo ufw disable
but didn't work.
I have no idea what to try next. How do I fix this?