简体   繁体   English

Ruby On Rails TCPSocket

[英]Ruby On Rails TCPSocket

I developed a server in C++ and I would like to develop an interface in Ruby On Rails. 我用C ++开发了一个服务器,我想用Ruby On Rails开发一个接口。

So I started to read http://ruby.railstutorial.org/ , meanwhile I start looking if I would be able to create a connection between my Ruby On Rails application and my server. 因此,我开始阅读http://ruby.railstutorial.org/ ,与此同时,我开始寻找是否能够在Ruby On Rails应用程序和服务器之间建立连接。
I find out I could use TCPSocket. 我发现我可以使用TCPSocket。

My question is : Could I open just 1 TCPSocket by session (and store it somewhere) ? 我的问题是:我可以按会话仅打开1个TCPSocket(并将其存储在某个地方)吗?
Or would I have to open a TCPSocket for every action in my controllers ? 还是我必须为控制器中的每个操作打开一个TCPSocket?

Thanks in advance, 提前致谢,

app/models/conn.rb: app / models / conn.rb:

class Conn
  @connection = "foo" # Connect here

  def self.get_connection
    @connection
  end
end

Rails console: Rails控制台:

irb(main):002:0> Conn.get_connection
=> "foo"

But unless your server is single-threaded you will have more than one connection anyways. 但是,除非您的服务器是单线程的,否则您将拥有多个连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM