I want to add a live notification in my application using Socket.io but I am having issues in integrating it in my application. When I run the application and looked at the browser log(console),
I have connection refused
(GET http://localhost:1500/socket.io/?EIO=3&transport=polling&t=1434954742052-24 net::ERR_CONNECTION_REFUSED)
my application is in localhost:130. I have read about CORS and applied the persmission in my controller.
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With,
Content - Type, Accept, Access - Control - Request - Method ");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "OPTIONS") {
die();
}
parent::__construct();
This is my server.js
var io = require('socket.io').listen(1500);
io.sockets.on('connection', function (socket) {
// Let everyone know it's working
socket.emit('startup', { message: 'I Am Working!!' });
});
This is my client.js
$(function() {
window.MY_Socket = {
// Instantiate the Socket.IO client and connect to the server
socket: io.connect('http://localhost:1500'),
// This just indicates that a Socket.IO connection has begun.
startupMessage: function(data) {
console.log(data.message);
},
}
});
Still I am receiving the error:net::ERR_CONNECTION_REFUSED
. I've been searching for work arround but I can still figure our how to solve this. Looking forward for you help