0

I'm attempting to write an IRC client using WebSockets. The IRC client I found on GitHub uses EventMachine, but I'm trying to use WebSockets as well to notify any connected clients when they're connected. However, I don't think I'm quite understanding EventMachine, because although the client successfully connects and joins the IRC channel, the puts 'Connected...' nor the subsequent line gets executed.

I assume this is because of a fundamental misunderstanding of EventMachine on my behalf.

EM.run {

  EventMachine::WebSocket.start(:host => '0.0.0.0', :port => 8080) do |websocket|

    websocket.onopen {

      irc = Net::YAIL.new(
          :address    => 'irc.my-example-server.net',
          :port       => 6667,
          :username   => 'MyExample',
          :realname   => 'My Example Bot',
          :nicknames  => ['MyExample1', 'MyExample2', 'MyExample3']
      )

      irc.on_welcome proc { |event|
        irc.join('#ExampleChannel')
        EM.next_tick {
          puts 'Connected...'
          websocket.send({ :message => 'Connected' })
        }
      }

      irc.start_listening!
    }

  end

}

4

1 回答 1

0

经过一夜的研究,我想我已经回答了自己的问题。本质上它与我对 EventMachine 的误解无关。只是我试图使用的 IRC 客户端只是一个无限循环,因此没有其他东西可以中断它。在为兼容 EventMachine 的 IRC 客户端研究了几个小时后,我遇到了 Ponder:https ://github.com/tbuehlmann/ponder所以现在希望我可以继续创建我的应用程序!

无耻插件:https ://github.com/Wildhoney/Banter.js

于 2013-08-18T01:29:57.843 回答