31 lines
762 B
Crystal
31 lines
762 B
Crystal
require "option_parser"
|
|
require "ipc"
|
|
require "./colors"
|
|
|
|
service_name = "pong"
|
|
|
|
OptionParser.parse! do |parser|
|
|
parser.on "-s service_name", "--service-name service_name", "URI" do |optsn|
|
|
service_name = optsn
|
|
end
|
|
|
|
parser.on "-h", "--help", "Show this help" do
|
|
puts parser
|
|
exit 0
|
|
end
|
|
end
|
|
|
|
|
|
IPC::Service.new (service_name) do |event|
|
|
case event
|
|
when IPC::Event::Connection
|
|
puts "#{CBLUE}IPC::Event::Connection#{CRESET}, client: #{event.connection.fd}"
|
|
when IPC::Event::Disconnection
|
|
puts "#{CBLUE}IPC::Event::Disconnection#{CRESET}, client: #{event.connection.fd}"
|
|
when IPC::Event::Message
|
|
puts "#{CGREEN}IPC::Event::Message#{CRESET}, client: #{event.connection.fd}"
|
|
# puts event.message.to_s
|
|
event.connection.send event.message
|
|
end
|
|
end
|