-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.rb
More file actions
46 lines (34 loc) · 826 Bytes
/
service.rb
File metadata and controls
46 lines (34 loc) · 826 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
46
require 'rubygems'
require 'eventmachine'
module ServiceTerminal
include EventMachine::Protocols::LineText2
@@connections = []
def receive_line(input)
@@connections.each do |client|
client.send_data "#{input}\n"
end
end
def self.attach_client(client)
@@connections << client
end
def self.detach_client(client)
@@connections.delete(client)
end
end
module ServiceConnection
def post_init
ServiceTerminal.attach_client(self)
end
def receive_data(data)
puts data
end
def unbind
ServiceTerminal.detach_client(self)
end
end
EventMachine.run {
Signal.trap("INT") { EventMachine.stop }
Signal.trap("TERM") { EventMachine.stop }
EventMachine.start_server("127.0.0.1", 5587, ServiceConnection)
EventMachine.open_keyboard(ServiceTerminal)
}