2011-02-26 49 views
0

我有服務器(WHM,紅寶石1.9.2,Rails 3.0.3,centOS,乘客),我只是部署我的RoR應用程序(它在本地計算機上工作),但我在生產模式中遇到奇怪的行爲。Ruby on Rails 3無法在生產模式下打開端口

我使用的是從

http://gimite.net/en/

web_socket.rb文件,當我想開始web套接字服務器:

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 

我沒有得到新的線程中運行。當我開始沒有「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 
+0

我試圖關閉Fire牆在我的服務器上,但沒有成功。 – dormitkon 2011-02-26 12:58:04

回答

0

我必須使用的後臺進程,而不是線程

+0

你能擴展這個答案嗎?我也有同樣的問題 – CustomNet 2013-11-10 15:38:48

0

可能是你的服務器具有IPV6本地主機

用戶127.0.0.1在/ etc/hosts中

它解決了我的問題