Forum: Ruby on Rails TCPSocket in controller action

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
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.
This topic is locked and can not be replied to.