Persistent TCP connection in a Rails application

I have a third-party server-based application that authenticates the client and responses.

My problem is here for every request I receive in my rails application I need to establish a TCP connection and get the data. Is it possible to have a permanent connection so that I can reduce the overhead of establishing a connection.

+5
source share
1 answer

Hope you are using a ruby ​​socket. I think you may have a method that will return a connection object. You may have a class variable for the connection object. the method will check if the connection then returns otherwise, create a new one.

 self.get_connection
   return @@conObj if @@conObj 
   return @@conObj = TCPSocket::new( "192.168.1.1", 100 )
 end

I'm not sure, but that might help you.

0
source

All Articles