Keeping objects alive while user is logged on

Let’s imagine we’re creating a web front end for a telnet/socket based
back service.

How should you implement this in rails so that when the user logs in to
the rails page, a socket connection is opened to the background service
from the web server and it will stay alive and available through
something like <%= @session[‘socksession’].readline %> while the user’s
session is active?

Don’t put too much effort in socket handling stuff since I’m not
actually
using sockets, I just think it is easier to get my question through
using
general socket connections as example.

I tried something like @session[‘sockconn’] =
Socket.open_socket(‘127.0.0.1’) but
trying to use @session[‘sockconn’].readline after that just gives
“uninitialized constant Socket”

I hope you understand what I’m trying to ask here.

I’m not sure if there’s any point in using rails in such app in the
first place since I’m not using any database stuff, what do you think?

Check out backgroundrb plugin ( http://backgroundrb.rubyforge.org/ )

This is a plugin that can run ruby code in seperate Threats as
so-called “workers”, which are basically ruby classes you can run in
the background.
You can start and access them through backgroundrb’s “MiddleMan”
fronend object
quote:
“The MiddleMan front object has a method that takes
a class type as a symbol and instantiates a new instance of said
class type. Then it returns a job_key to the client(rails). Rails can
then call a method on that object through the MiddleMan class.”

Then, until you delete the Worker Instance through MiddleMan, this
thread keeps running in the background, and you can access it by the
worker’s unique ID.

As i dont know what exactly you want to achieve, this may be a ver nice
solution or overkill.

Thorsten L wrote:

Check out backgroundrb plugin ( http://backgroundrb.rubyforge.org/ )

As i dont know what exactly you want to achieve, this may be a very
nice solution or overkill.

Seems like this is exactly what I want to achieve, thank you
for pointing that one out.