Forum: Ruby on Rails TCPSocket in controller action

1975f82475504c1102128d880f4f35c5?d=identicon&s=25 Dc Dieci (dcdieci)
on 2013-01-10 10:42
Hi,
in order to stream a file I am making use of TCPSocket. Unfortunately I
dont receive contents when in use the tcpsocket in a rails controller
action while it is working on console.

   url = "http://www.google.de"
   version   = request.env['HTTP_VERSION']
   verb      = request.env['REQUEST_METHOD']
   # url       = request.env['REQUEST_URI']
   puts url

   uri     = URI::parse url
   to_server = TCPSocket.new(uri.host, (uri.port.nil? ? 80 : uri.port))
   puts "#{verb} #{url} #{version}\r\n"
   to_server.write("#{verb} #{url} #{version}\r\n")
   puts to_server
   puts to_server.closed?


   puts "before while"
   #THIS LOOPS TAKES TOO LONG BECAUSE to_server.gets RETURNS EMTPY
   # while s = to_server.gets
   # puts s
   # end
   puts "close"
   to_server.close


Help is appreciated.
Best, Phil

I apologize for doing this double post on stackoverflow and here. but I
didn't get a response so far.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.