Reputation: 1439
I have created a simple app Laravel Homestead to test some basic stuff: Broadcasting events and listening them on socket.io.
Everything works well.
However, I want to upload the app to a remote server to a directory called learn-redis
and am facing a challenge. My socket.js file looks like this:
var server = require('http').Server();
var io = require('socket.io')(server);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('test-channel');
redis.on('message', function(channel, message){
message = JSON.parse(message);
io.emit(channel + ':' message.event, message.data);
});
server.listen(8000);
In Laravel Homestead, I know I can listen to port 8000 because it gets displays on the console when running vagrant up
. What about my remote server? What port do I use?
On client side, I have this code.
var socket = io('http://192.168.10.10:8000');
new Vue({
el: '#demo',
data: {
users: {!! App\User::all() !!}
},
ready: function(){
socket.on('test-channel:App\\Events\\UserSignedUp', function(data) {
this.users.push( data.user );
}.bind(this));
}
});
I have pulled Vue.js and Socket.io.js libraries, but when I try doing var socket = io('http://example.com/learn-redis:8000')
I get the error http://example.com:8000/socket.io/?EIO=3&transport=polling&t=LBWnq-U net::ERR_CONNECTION_TIMED_OUT
.
Upvotes: 1
Views: 1212
Reputation: 1104
You need to have a VPS server to be able to install node,most likely, You are on a shared hosting and most providers won't allow you to install node. Your best bet would be to ask your provider to install node for you or if you have the funds, upgrade to a VPS server.
Upvotes: 1