2007-07-05 19:11:00 UTC

Rubyology 35: Screencast - Ruby WebServer 3

Posted by @ChrisMatthieu

Download Screen Cast

ERB (Embedded Ruby)! This addition to our Ruby web server application allows you to call web pages with Ruby code that execute on the fly (time of render). Check out these snippets: myfile = IO.readlines("chris.html") #@session.puts myfile template = ERB.new <<-EOF #{myfile} EOF @session.puts template.result(binding)

2007-07-03 23:25:00 UTC

Rubyology 34: Screencast - Ruby WebServer 2

Posted by @ChrisMatthieu

Download Screen Cast

This is a continuation of the BYO-WebServer application except rather than outputing static text, we will read and output an html file stored in the same directory. The new 2 lines of code are as follows: myfile = IO.readlines("chris.html") @session.puts myfile Tune in next week for some ERB!

2007-06-26 23:40:00 UTC

Rubyology 33: Screencast - Ruby WebServer 1

Posted by @ChrisMatthieu

Download Screen Cast

By popular demand, here's a screencast of a basic web server engine based on Ruby. Source by Suresh Mahadevan. require 'thread' require 'socket' class RequestHandler def initialize(session) @session = session end def process while @session.gets.chop.length != 0 end @session.puts "HTTP/1.1 200 OK" @session.puts "content-type: text/html" @session.puts "" @session.puts "Hello World " @session.close end end server = TCPServer.new("0.0.0.0", "8888") while (session = server.accept) Thread.new(session) do |newSession| RequestHandler.new(newSession).process end end