开发者

Persistent TCP connection in Rails App

开发者 https://www.devze.com 2023-02-17 03:47 出处:网络
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 co

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号