require 'socket' # needed for Socket library require_relative 'protocol' # needed for custom binary protocol port = 9999 puts "Started UDP server on #{port}..." Socket.udp_server_loop(port) { |msg, msg_src| proto = CustomProtocol.new proto.read(msg) if proto.command_word == "ADD" puts "Received ADD command" result = proto.op1 + proto.op2 msg_src.reply result.to_s elsif proto.command_word == "MULT" puts "Received MULTIPLY command" result = proto.op1 * proto.op2 msg_src.reply result.to_s else puts "Received uknown cmd msg: #{proto.command_word} ..." end }