【问题标题】:Using WebSockets with EM and IRC to Send "Connection Successful" Message使用带有 EM 和 IRC 的 WebSockets 发送“连接成功”消息
【发布时间】:2013-08-17 22:56:49
【问题描述】:

我正在尝试使用 WebSockets 编写 IRC 客户端。我在 GitHub 上找到的 IRC 客户端使用 EventMachine,但我也尝试使用 WebSockets 在连接时通知任何连接的客户端。不过,我觉得我不是很了解 EventMachine,因为虽然客户端成功连接并加入了 IRC 频道,但puts 'Connected...' 和后续行都被执行了。

我认为这是因为我对 EventMachine 存在根本性的误解。

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

}

【问题讨论】:

    标签: ruby websocket eventmachine


    【解决方案1】:

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

    无耻塞:https://github.com/Wildhoney/Banter.js

    【讨论】:

    • 我是 Ponder 的作者,所以我只是给您留下一个关于该项目不再维护的说明。所以,保持警惕。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 2019-11-16
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    相关资源
    最近更新 更多