-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbenchmark_SRVR.rb
More file actions
46 lines (35 loc) · 1010 Bytes
/
benchmark_SRVR.rb
File metadata and controls
46 lines (35 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
class RequestHandler < EM::P::HeaderAndContentProtocol
$words='Con diez canones por banda viento en popa a toda vela
no corta el mar si no vuela un velero bergantin bajel
pirata llamado por su bravura el temido en todo el mar
conocido del uno al otro confin'.downcase.split
$words_length = $words.length
def poema(length)
r=[]
prev=''
curr=''
l = 0
while (l < length) do
begin
curr=$words[rand($words_length)]
end until (curr != prev)
l = l + curr.length + 1
r << (prev=curr)
end
return r.join(' ')
end
def receive_request headers, content
unPoema= "HOLA"
#unPoema= poema(4096)
send_data("HTTP/1.1 200 OK\nContent-Length: #{unPoema.length}\nServer: RUBY\n\n#{unPoema}")
close_connection_after_writing
end
end
EM.run{
port = 8080
EM.start_server 'localhost', port, RequestHandler
puts "RUBY Server running on port #{port}"
}