Ruby 构建一个最简单的 HTTP 服务器
- 作者: 晓明32485132
- 来源: 51数据库
- 2022-08-12
require 'socket' server = TCPServer.new("0.0.0.0", 80) loop do socket = server.accept while socket.gets.chop.length > 0 end socket.puts "HTTP/1.1 200 OK" socket.puts "Content-type: text/html" socket.puts "" socket.puts "<html>" socket.puts "<body>" socket.puts "<center>" socket.puts "<h1>#{Time.now}</h1>" socket.puts "</center>" socket.puts "</body>" socket.puts "</html>" socket.close end
推荐阅读