Persistent TCP connection in Rails App
I have a third party app running on a server, which authenticates the client and responses back.
My problem here is for each and every request that I get to my rails app I need to establish a TCP connection and get the data. Is it possible to have a persis开发者_StackOverflow中文版tent connection so that I can reduce overhead in establishing the connection.
I hope you are using ruby socket. I think you can have a method which will return a connection object. You can have a class variable for connection object. method will check if connection then return otherwise create new one.
self.get_connection
return @@conObj if @@conObj
return @@conObj = TCPSocket::new( "192.168.1.1", 100 )
end
I'm not sure but it might help you.
精彩评论