How to output binary data to a socket with Ruby
- by Earlz
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?