-
Notifications
You must be signed in to change notification settings - Fork 1
/
web.rb
65 lines (48 loc) · 1 KB
/
web.rb
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require 'rubygems'
gem "eventmachine"
gem "eventmachine_httpserver"
require './eval'
require './client'
require './commands'
require "eventmachine"
require "evma_httpserver"
class Client < EM::Connection
@@clients = {}
def unbind
@@clients.delete id
end
def initialize
@@clients[id] = self
end
def id
[self.hash].pack("Q").unpack("H*")[0]
end
def self.[](v)
@@clients[v]
end
def receive_data(data)
end
end
class MyHttpServer < EM::Connection
include EM::HttpServer
def post_init
super
no_environment_strings
end
def process_http_request
port, ip = Socket.unpack_sockaddr_in(get_peername)
p "#{ip}:#{port} #{@http_request_method} #{@http_path_info}"
response = EM::DelegatedHttpResponse.new(self)
response.status = 200
response.content_type 'text/html'
case @http_path_info
when "/connect"
else
response.status = 404
end
response.send_response
end
end
EM.run do
EM.start_server '::1', 8080, MyHttpServer
end