Question

I have faye implementation in my rails application. The publish method works correctly when both browsers are on the same computer. When I access the application from another browser on another computer, it only works from client to server and does not publish to other clients. Also the publish event does not push to client when there are changes in the browser on the server.
Controller publish code:

def publish(channel, data)
    message = {
      :channel => channel,
      :data => data,
      :ext => {:faye_token => FAYE_OUTGOING_AUTH_TOKEN}
    }
    uri = URI.parse('http://localhost:9292/faye')
    Net::HTTP.post_form(uri, :message => message.to_json)
end

Command to run faye:

rackup faye.ru -s thin -E production -d

Example:
A: Server, B: Client1, C: Client2

A B and C are different computers in same network, and are all subscribed to the same channel.

  1. If I input data on B, A will see the data but C will not see the data until I refresh the page (Which is getting the data from db).
  2. If I input data on A, it does not get published to the other clients.
  3. If I input data on C, to a channel that only C and B are subscribed to, only C gets to see the data, and it is not published to B.

If A, B, and C were different browsers on the same computer, all the above cases would work.

I have ran this in Development mode, and have tried WEBrick, Unicorn, and Thin.

Any help would be appreciated. Thanks.

Was it helpful?

Solution

To resolve the issue I replaced all instances of "localhost" with the address of the server on which Faye is running. This includes for subscribing clients to channels as well.

Hope it helps, Cheers!

OTHER TIPS

Hey Babak: I am also facing same kind of problem, I am using nodejs + express + faye. so I should add ip_addr:port to each subscribe,client

var client = new Faye.Client('/faye',{
        endpoints:{
                 websocket:'http:ws.chat-yummyfoods.rhcloud.com'
              }
        ,timeout: 20
    });
client.disable('websocket');
console.log("client:"+client);
var subscription=client.subscribe('/channel', function(message) {
        console.log("Message:"+message.text);
        $('#messages').append('<p>'+message.text+'</p>');
    });
subscription.then(function(){
        console.log('subscribe is active');
        alert('subscribe is active');
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top