I have installed node.js on my shared hosting with GoDaddy and can run node apps.
I don't exactly know where the problem is, but here's what's going on. I run the server, and it starts listening on a port (I tried a range from 49000
to 56000
).
But when the client tries to connect, i.e. access '/' on the server, the node is silent, therefore it doesn't receive any connection requests. So that kind of narrows it down to socket.io.
In the console within a few seconds it spits out this:
socket.io-1.4.5.js:1 GET http://website.com:55872/socket.io/?EIO=3&transport=polling&t=LQRdEP9 net::ERR_CONNECTION_TIMED_OUT
I have tried to source socket.io from the cdn as well as my own directory - nothing.
This is what the server looks like:
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
//------------- GLOBAL VARIABLES ---------------
SERVER_PORT = 55872;
connections = [];
//----------------------------------------------
server.listen(SERVER_PORT, "127.0.0.1");
console.log('................................................');
console.log('=> Server is listening on port: ' + SERVER_PORT);
console.log('................................................');
app.get('/', function(req, res){
console.log('=> Loading index.html!');
res.sendFile(__dirname + '/index.html');
});
// ----------- MIDDLEWARE ----------------------
// ----------- CONNECTIONS ---------------------
io.sockets.on('connection', function(socket){
connections.push(socket);
console.log('=> Client connected! Total connected: %s', connections.length);
// Disconnect socket
socket.on('disconnect', function(data){
connections.splice(connections.indexOf(socket), 1);
console.log('=> Client disconnected! Total connected: %s', connections.length);
});
Client:
$(function(){
//--------- SOCKET INIT --------------
var socket = io.connect('http://website.com:55872/');
});
Is the issue with socket.io or the node, or me...?