Reputation: 774
I want to push data to client using WebSocket. I dont now how to return data(from Redis) to client. Could somebody explain me that?
sockets_controller.rb
class SocketsController < WebsocketRails::BaseController
def create
send_message :new_event, {:message => 'TEST'}
end
end
events.rb
WebsocketRails::EventMap.describe do
subscribe :new_event, 'sockets#create'
end
websocket_rails.rb
WebsocketRails.setup do |config|
config.redis_options = { driver: :ruby }
config.standalone = false
config.synchronize = true
end
Client side:
$socket.on('test', function(data) {
console.log(data);
$scope.events.upshift(data);
if($scope.events.length>50){
$scope.events.length=50;
EventsList =$scope.events;
}
});
routerApp.config(["$socketProvider", function ($socketProvider) {
$socketProvider.setUrl("http://172.16.20.179:3000/events");
}]);
On the client side issue looks like:
GET http://172.16.20.179:3000/socket.io/?
EIO=3&transport=polling&t=1439215071732-9
XMLHttpRequest cannot load http://172.16.20.179:3000/socket.io/?
EIO=3&transport=polling&t=1439215056291-6. No 'Access-Control-Allow-
Origin' header is present on the requested resource. Origin
'http://localhost:4000' is therefore not allowed access. The response
had HTTP status code 404.
Upvotes: 1
Views: 248
Reputation: 6555
It seems that you are trying to use Socket.IO
for web-sockets. There are no supported implementation of Socket.IO
for Rails.
If you want an example on how to interact with websocket-rails from Angular.JS, you can use, for example, the following guide:
Upvotes: 1