Class: Opensips::MI::Transport::Datagram
- Defined in:
- lib/opensips/mi/transport/datagram.rb
Overview
datagram UDP transport to communicate with MI
Instance Method Summary collapse
-
#initialize(args) ⇒ Datagram
constructor
A new instance of Datagram.
- #send(command) ⇒ Object
Methods inherited from Abstract
#adapter_request, #adapter_response
Constructor Details
#initialize(args) ⇒ Datagram
Returns a new instance of Datagram.
12 13 14 15 16 17 18 19 20 |
# File 'lib/opensips/mi/transport/datagram.rb', line 12 def initialize(args) super() raise_invalid_params unless args.is_a?(Hash) @host, @port, @timeout = args.values_at(:host, :port, :timeout) raise_invalid_params if @host.nil? || @port.nil? raise_invalid_port unless @port.to_i.between?(1, 1 << 16) @timeout ||= 5 connect end |
Instance Method Details
#send(command) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/opensips/mi/transport/datagram.rb', line 22 def send(command) Timeout.timeout( @timeout, Opensips::MI::ErrorSendTimeout, "timeout send command to #{@host}:#{@port} within #{@timeout} sec" ) do @sock.send command, 0 msg, = @sock.recvfrom(1500) msg end end |