运行railscasts,windows 下 gem install eventmachine 出错

今天在github上把 http://railscasts.com/ 的源码拖了下来,bundle的时候出错了,

thin有个依赖 eventmachine,安装的时候出错,

看来windows下的gem install问题真不少,搜了一下,还是版本问题,

参考http://stackoverflow.com/questions/3649252/cannot-install-thin-on-windows

gem install eventmachine --pre
gem install thin

安装成功了,

但是bundle install的时候还是提示安装 eventmachine 0.12.10出错,于是在Gemfile里加上

gem "eventmachine","1.0.0.beta.3"

终于bundle成功,rails s  可以访问了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WebSockets in Ruby can be implemented using various libraries and frameworks. One popular library is `faye-websocket`, which provides a simple API for working with WebSockets in Ruby. To get started, you'll need to install the `faye-websocket` gem: ```bash gem install faye-websocket ``` Once installed, you can use the library to create a WebSocket server or client. Here's an example of how to create a WebSocket server using `faye-websocket`: ```ruby require 'faye/websocket' require 'eventmachine' EM.run { class MyWebSocketServer def initialize @clients = [] end def call(env) if Faye::WebSocket.websocket?(env) ws = Faye::WebSocket.new(env) ws.on :open do |event| @clients << ws end ws.on :message do |event| @clients.each { |client| client.send(event.data) } end ws.on :close do |event| @clients.delete(ws) ws = nil end # Return async Rack response ws.rack_response else # Handle non-WebSocket requests [200, { 'Content-Type' => 'text/plain' }, ['Hello']] end end end # Start the WebSocket server App = MyWebSocketServer.new Rack::Handler::Thin.run(App, Port: 8080) } ``` In this example, we create a WebSocket server using the `faye-websocket` library and the `EventMachine` event loop. The server listens on port 8080 and broadcasts any received messages to all connected clients. You can also create WebSocket clients using `faye-websocket`. Here's an example of how to create a WebSocket client: ```ruby require 'faye/websocket' require 'eventmachine' EM.run { ws = Faye::WebSocket::Client.new('ws://localhost:8080') ws.on :open do |event| puts 'Connected to server' ws.send('Hello server!') end ws.on :message do |event| puts "Received message: #{event.data}" end ws.on :close do |event| puts 'Disconnected from server' EM.stop end } ``` In this example, we create a WebSocket client using the `faye-websocket` library and the `EventMachine` event loop. The client connects to a WebSocket server running at `ws://localhost:8080`, sends a message, and prints any received messages. These examples should give you a basic understanding of how to use WebSockets in Ruby using the `faye-websocket` library. However, there are also other libraries available, such as `websocket-eventmachine-server` and `em-websocket`, which you can explore based on your specific requirements.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值