Permalink
Browse files

console port is random

  • Loading branch information...
1 parent ff0cb8d commit 3fbf39a027401dec8d4a6b96cbab05c7555080fd @jmmastey jmmastey committed Apr 20, 2012
Showing with 15 additions and 4 deletions.
  1. +15 −4 app/controllers/application_controller.rb
@@ -4,17 +4,17 @@ class ApplicationController < ActionController::Base
def command
# TODO: implement me
spawned = false
- port = 3001
+ port = get_console_port
- if !spawned
- spawn(port)
- end
+ spawn(port) if !spawned
response = communicate(port)
render :text => response
end
private
def spawn(port)
+ $stderr.puts "Spawning child on 127.0.0.1:#{port}"
+
fork do
server = TCPServer.new('127.0.0.1', port)
context = binding
@@ -51,4 +51,15 @@ def communicate(port)
"Hi"
end
+ def get_console_port(name = nil)
+ $stderr.print session[:tilde]
+ session[:tilde] ||= {}
+ session[:tilde][:consoles] ||= {}
+
+ unless session[:tilde][:consoles][name]
+ session[:tilde][:consoles][name] = (3000+rand(1000))
+ end
+ session[:tilde][:consoles][name]
+ end
+
end

0 comments on commit 3fbf39a

Please sign in to comment.