This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.
require'socket'
numCon=0
maxCon=10
defrespond(socket,code,body)# Genera prespuestas
socket.puts"HTTP/1.0 #{code}"
socket.puts"Content-type: text/html"
socket.puts"Content-length: #{body.length}"
socket.puts
socket.putsbody
socket.close
end
server=TCPServer.open(8080)
puts"web server created at port 8080"
loopdo
if(numCon<maxCon)
sock=server.accept# Acepta conexión del cliente
t=Thread.new(sock)do|socket|
numCon=numCon+1
request=socket.gets# Lee la primera línea
o=socket.getsuntil(o!="")# cabecera acaba con línea vacía
unlessrequest=~/^GET/# Si el comando no esta soportado
respondsocket,"400 Bad Request","<html><body><h1>Comando desconocido</h1></body></html>"
next# Acaba el ciclo
end
request=~/^GET \/(.*) .*/# GET /(fichero) HTTP/1.x