Ruby on Rails 3 无法在生产模式下打开端口
我有服务器(WHM、ruby 1.9.2、Rails 3.0.3、centOS、passenger),我只是部署我的 RoR 应用程序(它在本地计算机上运行),但我在生产模式下遇到奇怪的行为。
我正在使用 web_socket.rb 文件
当我想启动网络套接字服务器时:
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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我必须使用后台进程而不是线程
I must to use background processes instead of Threads
可能你的服务器
在 /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