Obsolete
/
ipcd
Archived
3
0
Fork 0

pongd is now an IPC service real-life example

master
Philippe PITTOLI 2020-01-16 17:31:26 +01:00
parent 63d2999ccb
commit 02a6ac97c1
1 changed files with 17 additions and 6 deletions

View File

@ -20,8 +20,9 @@ OptionParser.parse do |parser|
end end
end end
service = IPC::Service.new (service_name)
IPC::Service.new (service_name) do |event| service.loop do |event|
case event case event
when IPC::Event::Timer when IPC::Event::Timer
if verbosity >= 1 if verbosity >= 1
@ -36,13 +37,23 @@ IPC::Service.new (service_name) do |event|
puts "#{CBLUE}IPC::Event::Disconnection#{CRESET}, client: #{event.connection.fd}" puts "#{CBLUE}IPC::Event::Disconnection#{CRESET}, client: #{event.connection.fd}"
end end
when IPC::Event::Message when IPC::Event::Message
if verbosity >= 1 begin
puts "#{CGREEN}IPC::Event::Message#{CRESET}, client: #{event.connection.fd}" if verbosity >= 1
if verbosity == 2 puts "#{CGREEN}IPC::Event::Message#{CRESET}, client: #{event.connection.fd}"
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 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 end
event.connection.send event.message
else else
if verbosity >= 1 if verbosity >= 1
puts "#{CRED}Exception: message = #{event.message} #{CRESET}" puts "#{CRED}Exception: message = #{event.message} #{CRESET}"