Sha256: 0c6f3e0d8493aace488940a7ccf9414d68b7b680e928f7d72891a67def2ba032

Contents?: true

Size: 608 Bytes

Versions: 1

Compression:

Stored size: 608 Bytes

Contents

require 'socket'
require_relative '../addr'
require_relative 'sock'

module Kamerling
  module Server
    class UDP < Sock
      private

      def handle_connection(socket)
        input, conn = socket.recvfrom 2**16
        client_addr = Addr[conn[3], conn[1], :UDP]
        handle input, client_addr
      end

      def run_loop
        socket = UDPSocket.new.tap { |server| server.bind(*addr) }
        loop { handle_connection socket if IO.select [socket] }
      ensure
        socket.close if socket
      end

      def wait_till_started
        200.times { thread.run }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kamerling-0.0.3 lib/kamerling/server/udp.rb