I tried to use socket.io with EC2 and laravel.
Here's my code in server side - server.js
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var redis = require('redis');
console.log("hello");
server.listen(8890, function(){
console.log("8890");
});
io.sockets.on('connection', function (socket) {
console.log("connected");
});
When I test in localhost, everything is fine. I can connect and emit.
When I node server.js
in localhost, the result will be like this.
hello
8890
connected
But when I node server.js
in EC2 instance, the result will be like this. Seems like it cannot connect the socket.io.
hello
8890
I have already install redis, node, npm and express in the EC2 instance and tested they are running.
I had also set the security group of my instance for port 8890 like this.
Type Protocol Port Range Source
HTTP TCP 80 0.0.0.0/0
Custom TCP Rule TCP 8890 0.0.0.0/0
SSH TCP 22 0.0.0.0/0
Am i missing any steps? Please help. Thanks a lot.