lib/kamerling/server/udp.rb in kamerling-0.0.2 vs lib/kamerling/server/udp.rb in kamerling-0.0.3
- old
+ new
@@ -1,20 +1,28 @@
-module Kamerling module Server class UDP < Sock
- private
+require 'socket'
+require_relative '../addr'
+require_relative 'sock'
- def handle_connection socket
- input, conn = socket.recvfrom 2**16
- client_addr = Addr[conn[3], conn[1], :UDP]
- handle input, client_addr
- end
+module Kamerling
+ module Server
+ class UDP < Sock
+ private
- 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 handle_connection(socket)
+ input, conn = socket.recvfrom 2**16
+ client_addr = Addr[conn[3], conn[1], :UDP]
+ handle input, client_addr
+ end
- def wait_till_started
- 200.times { thread.run }
+ 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 end end
+end