Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
Sending Binary Data?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Robert Klemme" data-source="post: 4506871"><p>This approach is quite inefficient in two ways:</p><p></p><p>- you use + for string concatenation which constantly creates new objects</p><p>and throws old ones away. Better use <<</p><p></p><p>- You need to keep the whole file in mem while with a streaming approach</p><p>(reading and writing a chunk at a time only) you can deal with arbitrary</p><p>sized files without worrying about memory.</p><p></p><p></p><p>You should use mode "wb" - even if on Linux.</p><p></p><p></p><p>"wb" again...</p><p></p><p></p><p>Better use #read and #write instead of gets!</p><p></p><p></p><p>You want TCPServer here.</p><p></p><p></p><p># untested</p><p>srv = TCPServer.new('localhost',9191)</p><p></p><p>while ( sess = srv.accept )</p><p>Thread.new(sess) do |session|</p><p>File.open("lighter.jpg", "rb") |io|</p><p>session.write(io.read(1024))</p><p>end</p><p>end</p><p>end</p><p></p><p></p><p>Hope I could give some valuable hints.</p><p></p><p>Kind regards</p><p></p><p>robert</p></blockquote><p></p>
[QUOTE="Robert Klemme, post: 4506871"] This approach is quite inefficient in two ways: - you use + for string concatenation which constantly creates new objects and throws old ones away. Better use << - You need to keep the whole file in mem while with a streaming approach (reading and writing a chunk at a time only) you can deal with arbitrary sized files without worrying about memory. You should use mode "wb" - even if on Linux. "wb" again... Better use #read and #write instead of gets! You want TCPServer here. # untested srv = TCPServer.new('localhost',9191) while ( sess = srv.accept ) Thread.new(sess) do |session| File.open("lighter.jpg", "rb") |io| session.write(io.read(1024)) end end end Hope I could give some valuable hints. Kind regards robert [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
Sending Binary Data?
Top