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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -