Where to place a socket within a rails app? -
i have rails-based webapp , unity-based app. these have communicate each other on udp-socket.
where best place within rails app create such socket? me necessary socket exist before user visits webapp , socket accessible within controller.
in rails files under config/initializers
loaded when application starts.
so 1 way want create new file there initializes socket connection , assign constant rest of application uses.
class utility def self.socket_connection @connection ||= connect_socket end def self.connect_socket # logic connecting socket end end
and later when need connection use utility.socket_connection
if "real" application, need more sophisticated approach that:
- pools connections handle when different parts of applications want use socket connections @ same time. (they'd check out & in connection, how activerecord's
#with_connection
works - monitor connections, closing , re-establishing them necessary
Comments
Post a Comment