Sha256: 7a7d0c1fc6d380226d85a9aa1d2a77d9bc5329a52d951189245595a1e2d08506

Contents?: true

Size: 690 Bytes

Versions: 5

Compression:

Stored size: 690 Bytes

Contents

module Kurchatov
  module Responders
    class Udp < Kurchatov::Plugin

      include Kurchatov::Mixin::Event

      def initialize(conn)
        @host, @port = conn.split(':')
        @name = "udp responder #{@host}:#{@port}"
      end


      def run
        Socket.udp_server_loop(@host, @port) do |data, src|
          process(data, src)
        end
      end

      def process(data, src)
        begin
          event(JSON.parse(data))
          src.reply "sended\n\n"
        rescue => e
          src.reply "failed to send: #{data.inspect}\n"
          Log.error("Failed parse #{data.inspect}, #{e.class}: #{e}\n #{e.backtrace.join("\n")}")
        end
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kurchatov-0.0.6.pre.4 lib/kurchatov/responders/udp.rb
kurchatov-0.0.6.pre.3 lib/kurchatov/responders/udp.rb
kurchatov-0.0.6.pre.2 lib/kurchatov/responders/udp.rb
kurchatov-0.0.6.pre.1 lib/kurchatov/responders/udp.rb
kurchatov-0.0.5 lib/kurchatov/responders/udp.rb