在Python Twisted中,您可以使用twistd命令帮助您完成与运行应用程序相关的许多事情(例如,将其守护进程).
如何守护node.js服务器,以便即使在当前会话关闭后它也可以运行?
谢谢你的帮助
使用Mongoid,假设我有以下类:
class Map
include Mongoid::Document
embeds_many :locations
end
class Location
include Mongoid::Document
field :x_coord, :type => Integer
field :y_coord, :type => Integer
embedded_in :map, :inverse_of => :locations
end
class Player
include Mongoid::Document
references_one :location
end
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我正在尝试建模一个简单的游戏世界环境,其中地图嵌入位置,并且玩家将单个位置作为当前位置.
使用这种方法,当我尝试引用Player类的"location"属性时,我收到以下错误:
Mongoid::Errors::DocumentNotFound: Document not found for class Location with id(s) xxxxxxxxxxxxxxxxxxx.
Run Code Online (Sandbox Code Playgroud)
我的理解是,这是因为位置文档是嵌入式的,因此很难在其嵌入文档(Map)的范围之外引用.这是有道理的,但我如何建模对嵌入式文档的直接引用?
我有一个socket.io客户端连接到node.js服务器.如果我在命令行中杀死node.js,客户端会立即冻结(即通信停止),但在"disconnect"事件被触发之前有大约20秒的延迟.这种行为是设计的吗?是否有配置选项来减少触发断开连接事件的延迟?
看来这种行为在socket.io的最新(最近6个月)更新中发生了变化.在重新连接功能内置到socket.io本身之前,我使用"disconnect"事件处理程序实现了我自己的重新连接逻辑,并且当服务器通信暂停时,"disconnect"事件几乎立即触发.