How to output binary data to a socket with Ruby
Posted
by Earlz
on Stack Overflow
See other posts from Stack Overflow
or by Earlz
Published on 2010-05-25T07:08:32Z
Indexed on
2010/05/25
7:11 UTC
Read the original article
Hit count: 359
Hello I have a very simple HTTP ruby server. I want it to simply server a PNG image. So I sent headers like image/png but I think that Ruby is converting the image data to a string first.
Here is my relevant code
webserver = TCPServer.new('127.0.0.1', 20001)
while (session = webserver.accept)
#....
file = File.open("tmp_testserve.png", "rb")
contents = file.read
file.close
session.print @content
session.close
#....
Is this what is happening?
© Stack Overflow or respective owner