Reputation: 11091
I need to
so I thought I am going to write a web/application server in ruby. But I do not know where to start.
The computer that will run ant is Win XP SP3 and there is no web server or anything else running.
I found this code but not sure which part to modify so I does what I want. Let's say I want to run "dir" command and send back to the browser result of that command.
require 'socket'
webserver = TCPServer.new('127.0.0.1', 7125)
while (session = webserver.accept)
session.print "HTTP/1.1 200/OK\r\nContent-type:text/html\r\n\r\n"
request = session.gets
trimmedrequest = request.gsub(/GET\ \//, '').gsub(/\ HTTP.*/, '')
filename = trimmedrequest.chomp
if filename == ""
filename = "index.html"
end
begin
displayfile = File.open(filename, 'r')
content = displayfile.read()
session.print content
rescue Errno::ENOENT
session.print "File not found"
end
session.close
end
Upvotes: 0
Views: 401
Reputation: 1609
Ruby includes a Web server (WEBrick) so you don't actually need to use the code that you posted. Sinatra is designed specifically for writing very small Web applications - it lets you write a Web application in a few lines of code and automatically uses the provided Web server.
Upvotes: 1
Reputation: 41
You can use ruby web server such as Rack, Webrick, mongrel, also you can use Ruby on Rails, Sinatra what else you want.
Of course you can write code from scratch, but it's not good idea to write whole by your own.
Upvotes: 1