Ruby on Rails 3 无法在生产模式下打开端口

发布于 2024-10-19 11:36:56 字数 1654 浏览 1 评论 0原文

我有服务器(WHM、ruby 1.9.2、Rails 3.0.3、centOS、passenger),我只是部署我的 RoR 应用程序(它在本地计算机上运行),但我在生产模式下遇到奇怪的行为。

我正在使用 web_socket.rb 文件

http://gimite.net/en/

当我想启动网络套接字服务器时:

Thread.start {  
 @sockets = []
      Thread.abort_on_exception = true
      server = WebSocketServer.new( :accepted_domains => "*", :port => session[:port])
      logger.debug "Server is running at port %d" % server.port   



  server.run() do |ws|


    puts("Connection accepted")
    puts("Path: #{ws.path}, Origin: #{ws.origin}")

    if ws.path == "/"
      ws.handshake()
      @sockets << ws
      while data = ws.receive()

        printf("Received: %p\n", data)

          @sockets.each {|s| s.send(data)}

        printf("Sent: %p\n", data)
      end
    else
      ws.handshake("404 Not Found")
    end
    puts("Connection closed")
  end
  }
end

我不' t 让新线程运行。当我在没有“Thread.start”的情况下开始时,我收到此错误:

Errno::EAFNOSUPPORT (Address family not supported by protocol - socket(2)):
  lib/web_socket.rb:314:in `initialize'
  lib/web_socket.rb:314:in `open'
  lib/web_socket.rb:314:in `initialize'
  app/controllers/access_controller.rb:53:in `new'
  app/controllers/access_controller.rb:53:in `socket'
  app/controllers/access_controller.rb:29:in `attempt_login'

我试图找出问题所在,但我被卡住了:|

我怎么知道端口可能有问题?

因为在web_socket.rb中,第314行是:

if params[:host]
        @tcp_server = TCPServer.open(params[:host], @port)
      else
        @tcp_server = TCPServer.open(@port)
      end

I have server (WHM, ruby 1.9.2, Rails 3.0.3, centOS, passenger) and I just deploy my RoR app (it works on local computer) but I get strange behavior in production mode.

I'm using web_socket.rb file from

http://gimite.net/en/

and when I want to start web socket server with:

Thread.start {  
 @sockets = []
      Thread.abort_on_exception = true
      server = WebSocketServer.new( :accepted_domains => "*", :port => session[:port])
      logger.debug "Server is running at port %d" % server.port   



  server.run() do |ws|


    puts("Connection accepted")
    puts("Path: #{ws.path}, Origin: #{ws.origin}")

    if ws.path == "/"
      ws.handshake()
      @sockets << ws
      while data = ws.receive()

        printf("Received: %p\n", data)

          @sockets.each {|s| s.send(data)}

        printf("Sent: %p\n", data)
      end
    else
      ws.handshake("404 Not Found")
    end
    puts("Connection closed")
  end
  }
end

I don't get new Thread running. When I start without "Thread.start" I get this error:

Errno::EAFNOSUPPORT (Address family not supported by protocol - socket(2)):
  lib/web_socket.rb:314:in `initialize'
  lib/web_socket.rb:314:in `open'
  lib/web_socket.rb:314:in `initialize'
  app/controllers/access_controller.rb:53:in `new'
  app/controllers/access_controller.rb:53:in `socket'
  app/controllers/access_controller.rb:29:in `attempt_login'

I trying to figure out what is the problem, but I'm stuck :|

How do I know that port is maybe problem?

Because in web_socket.rb, line 314 is:

if params[:host]
        @tcp_server = TCPServer.open(params[:host], @port)
      else
        @tcp_server = TCPServer.open(@port)
      end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小镇女孩 2024-10-26 11:36:56

我必须使用后台进程而不是线程

I must to use background processes instead of Threads

水晶透心 2024-10-26 11:36:56

可能你的服务器

在 /etc/hosts 中有本地主机用户 127.0.0.1

的 IPV6它解决了我的问题

May be your server has IPV6 for localhost

user 127.0.0.1 in /etc/hosts

it solved my problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文