jcoglan/faye — Issue #117: faye ruby client is not working
Author: nazarhussain
Created: 2011-12-20 08:06:42+00:00
State: open

I am using faye on my Rails 2.1 app. And after testing and fixing many things faye ruby cleint is not working.

This is my server code.

```ruby
require 'faye'

server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45)

EM.run {
thin = Rack::Handler.get('thin')
thin.run(server, :Port => 9292)

server.bind(:subscribe) do |client_id, channel|
puts "[ SUBSCRIBE] #{client_id} -> #{channel}"
end

server.bind(:unsubscribe) do |client_id, channel|
puts "[UNSUBSCRIBE] #{client_id} -> #{channel}"
end

server.bind(:disconnect) do |client_id|
puts "[ DISCONNECT] #{client_id}"
end
}
```

This is my client side JS code.

``` javascript

```

This is ruby client code.

```ruby
EM.run do
client = Faye::Client.new('http://localhost:9292/faye')
publication = client.publish("/faye/new_chats", {
"user" => "ruby-logger",
"message" => "Got your message!"
})
publication.callback do
puts "[PUBLISH SUCCEEDED]"
end
publication.errback do |error|
puts "[PUBLISH FAILED] #{error.inspect}"
end
end
```
Server, JS is working fine. But Ruby client code is not working. If i write it with out EM it shows me the error that Event Machine not initialized. If i write it in EM it works but haults the ruby process. If i put EM.stop at the end of client code executes but do not publish the message.

How can i solve this issue.