Simultaneous HTTP connect with EventMachine

Can anyone give many any tips about how to have multiple
EventMachine.connect instances running at the same time? I thought
em-synchrony looked promising, but it only works with
EventMachine::HttpRequest.

I need EventMachine.connect because my application streams http data
using the receive_data callback, which EventMachine::HttpRequest lacks.

If I try running more than one streaming EventMachine.connect normally
inside EM.run, I only see the results of the last EventMachine.connect.
(even if I run this in a separate thread still only shows the results of
the last .connect)

help?

On Thu, Feb 10, 2011 at 12:03 PM, Shea B. [email protected] wrote:

Can anyone give many any tips about how to have multiple
EventMachine.connect instances running at the same time? I thought
em-synchrony looked promising, but it only works with
EventMachine::HttpRequest.

I need EventMachine.connect because my application streams http data
using the receive_data callback, which EventMachine::HttpRequest lacks.

If I try running more than one streaming EventMachine.connect normally
inside EM.run, I only see the results of the last EventMachine.connect

You are doing something wrong.

EM.connect, just like everything else in EM, is asynchronous. You can
connect to many places at the same time. I’ve done tests with 20000
connections before.

As for receive_data, all connection handlers have a receive_data,
since that is what EM calls when it receives a chunk of data. If the
handler descends from EventMachine::Connection, it will have a default
receive_data defined for it.

However:

https://github.com/eventmachine/em-http-request/blob/master/lib/em-http/client.rb#L226

You need to provide more details about what you are doing before
anyone is going to be able to tell you what you are doing wrong.

Kirk H.
Software Developer
Engine Y.

More details:

Im trying to use Twitter::JSONStream, which is an
EventMachine::Connection to simultaneously watch two different twitter
filters using the streaming API.

gem ‘twitter-stream’

require ‘twitter/json_stream’
EM.run do
a = Twitter::JSONStream.connect :path =>
“/1/statuses/filter.json?track=:)”, :auth => “username:password”
b = Twitter::JSONStream.connect :path =>
“/1/statuses/filter.json?track=:(”, :auth => “username:password”

a.each_item {puts “happy” }
b.each_item {puts “unhappy” }

end

This should be printing alternating happy and unhappy, but right now it
only prints one of the two

This is my first time actually using EventMachine. thanks for the help.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs