pongd is now an IPC service real-life example
parent
63d2999ccb
commit
02a6ac97c1
17
src/pongd.cr
17
src/pongd.cr
|
@ -20,8 +20,9 @@ OptionParser.parse do |parser|
|
|||
end
|
||||
end
|
||||
|
||||
service = IPC::Service.new (service_name)
|
||||
|
||||
IPC::Service.new (service_name) do |event|
|
||||
service.loop do |event|
|
||||
case event
|
||||
when IPC::Event::Timer
|
||||
if verbosity >= 1
|
||||
|
@ -36,13 +37,23 @@ IPC::Service.new (service_name) do |event|
|
|||
puts "#{CBLUE}IPC::Event::Disconnection#{CRESET}, client: #{event.connection.fd}"
|
||||
end
|
||||
when IPC::Event::Message
|
||||
begin
|
||||
if verbosity >= 1
|
||||
puts "#{CGREEN}IPC::Event::Message#{CRESET}, client: #{event.connection.fd}"
|
||||
if verbosity == 2
|
||||
puts "#{CBLUE}message: #{event.message} #{CRESET}"
|
||||
if verbosity >= 2
|
||||
m = String.new event.message.payload
|
||||
puts "#{CBLUE}message type #{event.message.type}: #{m} #{CRESET}"
|
||||
end
|
||||
end
|
||||
event.connection.send event.message
|
||||
if verbosity >= 2
|
||||
puts "#{CBLUE}message sent#{CRESET}"
|
||||
end
|
||||
|
||||
rescue e
|
||||
puts "#{CRED}#{e.message}#{CRESET}"
|
||||
service.remove_fd event.connection.fd
|
||||
end
|
||||
else
|
||||
if verbosity >= 1
|
||||
puts "#{CRED}Exception: message = #{event.message} #{CRESET}"
|
||||
|
|
Reference in New Issue