Class List Method List File List

# Class: Vertx::DatagramSocket

Inherits:
  Object
  - Object
  - Vertx::DatagramSocket
  show all
Includes:
  Measured, ReadStream
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb

## Overview

A datagram socket can be used to send DatagramPacket's to remote datagram servers and receive {::Vertx::DatagramPacket}s .

Usually you use a datagram socket to send UDP over the wire. UDP is connection-less which means you are not connected to the remote peer in a persistent way. Because of this you have to supply the address and port of the remote peer when sending data.

You can send data to ipv4 or ipv6 addresses, which also include multicast addresses.

Please consult the documentation for more information on datagram sockets.

## Instance Method Summary (collapse)

- - (self) block_multicast_group(multicastAddress = nil, networkInterface = nil, sourceToBlock = nil) { ... }
  Block the given address for the given multicast address on the given network interface and notifies the once the operation completes.
- - (void) close { ... }
  Closes the DatagramSocket implementation asynchronous and notifies the handler once done.
- - (self) end_handler { ... }
- - (self) exception_handler { ... }
- - (self) handler { ... }
- - (self) listen(port = nil, host = nil) { ... }
  Start listening on the given port and host.
- - (self) listen_multicast_group(multicastAddress = nil, networkInterface = nil, source = nil) { ... }
  Joins a multicast group and listens for packets send to it on the given network interface.
- - (::Vertx::SocketAddress) local_address
  Return the SocketAddress to which this DatagramSocket is bound.
- - (true, false) metrics_enabled?
  Whether the metrics are enabled for this measured object.
- - (self) pause
- - (self) resume
- - (self) send(param_1 = nil, param_2 = nil, param_3 = nil, param_4 = nil)
  Write the given String to the SocketAddress using the given encoding.
- - (::Vertx::PacketWritestream) sender(port = nil, host = nil)
  Returns a PacketWritestream able to send to the SocketAddress.
- - (self) unlisten_multicast_group(multicastAddress = nil, networkInterface = nil, source = nil) { ... }
  Leaves a multicast group and stops listening for packets send to it on the given network interface.

## Instance Method Details

### - (`self`) block_multicast_group(multicastAddress = nil, networkInterface = nil, sourceToBlock = nil) { ... }

Block the given address for the given multicast address on the given network interface and notifies the once the operation completes.

Parameters:

- multicastAddress (`String`) (defaults to: `nil`) —
  the address for which you want to block the source address
- networkInterface (`String`) (defaults to: `nil`) —
  the network interface on which the blocking should occur.
- sourceToBlock (`String`) (defaults to: `nil`) —
  the source address which should be blocked. You will not receive an multicast packets for it anymore.

Yields:

- the handler to notify once the operation completes

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 149

    def block_multicast_group(multicastAddress=nil,networkInterface=nil,sourceToBlock=nil)
      if multicastAddress.class == String && networkInterface.class == String && block_given? && sourceToBlock == nil
        @j_del.java_method(:blockMulticastGroup, [Java::java.lang.String.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(multicastAddress,networkInterface,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::DatagramSocket) : nil) }))
        return self
      elsif multicastAddress.class == String && networkInterface.class == String && sourceToBlock.class == String && block_given?
        @j_del.java_method(:blockMulticastGroup, [Java::java.lang.String.java_class,Java::java.lang.String.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(multicastAddress,networkInterface,sourceToBlock,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::DatagramSocket) : nil) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling block_multicast_group(multicastAddress,networkInterface,sourceToBlock)"
    end

### - (`void`) close { ... }

This method returns an undefined value.

Closes the Vertx::DatagramSocket implementation asynchronous and notifies the handler once done.

Yields:

- the handler to notify once complete

Raises:

- (`ArgumentError`)

    88
    89
    90
    91
    92
    93
    94
    95
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 88

    def close
      if !block_given?
        return @j_del.java_method(:close, []).call()
      elsif block_given?
        return @j_del.java_method(:close, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil) }))
      end
      raise ArgumentError, "Invalid arguments when calling close()"
    end

### - (`self`) end_handler { ... }

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    189
    190
    191
    192
    193
    194
    195
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 189

    def end_handler
      if block_given?
        @j_del.java_method(:endHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield })
        return self
      end
      raise ArgumentError, "Invalid arguments when calling end_handler()"
    end

### - (`self`) exception_handler { ... }

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    207
    208
    209
    210
    211
    212
    213
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 207

    def exception_handler
      if block_given?
        @j_del.java_method(:exceptionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.from_throwable(event)) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling exception_handler()"
    end

### - (`self`) handler { ... }

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    198
    199
    200
    201
    202
    203
    204
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 198

    def handler
      if block_given?
        @j_del.java_method(:handler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::DatagramPacket)) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling handler()"
    end

### - (`self`) listen(port = nil, host = nil) { ... }

Start listening on the given port and host. The handler will be called when the socket is listening.

Parameters:

- port (`Fixnum`) (defaults to: `nil`) —
  the port to listen on
- host (`String`) (defaults to: `nil`) —
  the host to listen on

Yields:

- the handler will be called when listening

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    164
    165
    166
    167
    168
    169
    170
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 164

    def listen(port=nil,host=nil)
      if port.class == Fixnum && host.class == String && block_given?
        @j_del.java_method(:listen, [Java::int.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(port,host,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::DatagramSocket) : nil) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling listen(port,host)"
    end

### - (`self`) listen_multicast_group(multicastAddress = nil, networkInterface = nil, source = nil) { ... }

Joins a multicast group and listens for packets send to it on the given network interface. The is notified once the operation completes.

Parameters:

- multicastAddress (`String`) (defaults to: `nil`) —
  the address of the multicast group to join
- networkInterface (`String`) (defaults to: `nil`) —
  the network interface on which to listen for packets.
- source (`String`) (defaults to: `nil`) —
  the address of the source for which we will listen for multicast packets

Yields:

- then handler to notify once the operation completes

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 115

    def listen_multicast_group(multicastAddress=nil,networkInterface=nil,source=nil)
      if multicastAddress.class == String && block_given? && networkInterface == nil && source == nil
        @j_del.java_method(:listenMulticastGroup, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(multicastAddress,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::DatagramSocket) : nil) }))
        return self
      elsif multicastAddress.class == String && networkInterface.class == String && source.class == String && block_given?
        @j_del.java_method(:listenMulticastGroup, [Java::java.lang.String.java_class,Java::java.lang.String.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(multicastAddress,networkInterface,source,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::DatagramSocket) : nil) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling listen_multicast_group(multicastAddress,networkInterface,source)"
    end

### - (`::Vertx::SocketAddress`) local_address

Return the SocketAddress to which this Vertx::DatagramSocket is bound.

Returns:

- (`::Vertx::SocketAddress`) —
  the socket address

Raises:

- (`ArgumentError`)

    99
    100
    101
    102
    103
    104
    105
    106
    107
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 99

    def local_address
      if !block_given?
        if @cached_local_address != nil
          return @cached_local_address
        end
        return @cached_local_address = ::Vertx::Util::Utils.safe_create(@j_del.java_method(:localAddress, []).call(),::Vertx::SocketAddress)
      end
      raise ArgumentError, "Invalid arguments when calling local_address()"
    end

### - (`true`, `false`) metrics_enabled?

Whether the metrics are enabled for this measured object

Returns:

- (`true`, `false`) —
  true if the metrics are enabled

Raises:

- (`ArgumentError`)

    35
    36
    37
    38
    39
    40
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 35

    def metrics_enabled?
      if !block_given?
        return @j_del.java_method(:isMetricsEnabled, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling metrics_enabled?()"
    end

### - (`self`) pause

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    172
    173
    174
    175
    176
    177
    178
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 172

    def pause
      if !block_given?
        @j_del.java_method(:pause, []).call()
        return self
      end
      raise ArgumentError, "Invalid arguments when calling pause()"
    end

### - (`self`) resume

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    180
    181
    182
    183
    184
    185
    186
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 180

    def resume
      if !block_given?
        @j_del.java_method(:resume, []).call()
        return self
      end
      raise ArgumentError, "Invalid arguments when calling resume()"
    end

### - (`self`) send(packet, port, host, handler) - (`self`) send(str, port, host, handler) - (`self`) send(str, enc, port, host, handler)

Write the given String to the SocketAddress using the given encoding. The will be notified once the write completes.

Overloads:

- - (`self`) send(packet, port, host, handler)

  Parameters:

  - packet (`::Vertx::Buffer`) —
    the Buffer to write
  - port (`Fixnum`) —
    the host port of the remote peer
  - host (`String`) —
    the host address of the remote peer
- - (`self`) send(str, port, host, handler)

  Parameters:

  - str (`String`) —
    the String to write
  - port (`Fixnum`) —
    the host port of the remote peer
  - host (`String`) —
    the host address of the remote peer
- - (`self`) send(str, enc, port, host, handler)

  Parameters:

  - str (`String`) —
    the String to write
  - enc (`String`) —
    the charset used for encoding
  - port (`Fixnum`) —
    the host port of the remote peer
  - host (`String`) —
    the host address of the remote peer

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 60

    def send(param_1=nil,param_2=nil,param_3=nil,param_4=nil)
      if param_1.class.method_defined?(:j_del) && param_2.class == Fixnum && param_3.class == String && block_given? && param_4 == nil
        @j_del.java_method(:send, [Java::IoVertxCoreBuffer::Buffer.java_class,Java::int.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(param_1.j_del,param_2,param_3,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::DatagramSocket) : nil) }))
        return self
      elsif param_1.class == String && param_2.class == Fixnum && param_3.class == String && block_given? && param_4 == nil
        @j_del.java_method(:send, [Java::java.lang.String.java_class,Java::int.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(param_1,param_2,param_3,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::DatagramSocket) : nil) }))
        return self
      elsif param_1.class == String && param_2.class == String && param_3.class == Fixnum && param_4.class == String && block_given?
        @j_del.java_method(:send, [Java::java.lang.String.java_class,Java::java.lang.String.java_class,Java::int.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(param_1,param_2,param_3,param_4,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::DatagramSocket) : nil) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling send(param_1,param_2,param_3,param_4)"
    end

### - (`::Vertx::PacketWritestream`) sender(port = nil, host = nil)

Returns a PacketWritestream able to send to the SocketAddress.

Parameters:

- port (`Fixnum`) (defaults to: `nil`) —
  the port of the remote peer
- host (`String`) (defaults to: `nil`) —
  the host address of the remote peer

Returns:

- (`::Vertx::PacketWritestream`) —
  the write stream for sending packets

Raises:

- (`ArgumentError`)

    78
    79
    80
    81
    82
    83
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 78

    def sender(port=nil,host=nil)
      if port.class == Fixnum && host.class == String && !block_given?
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:sender, [Java::int.java_class,Java::java.lang.String.java_class]).call(port,host),::Vertx::PacketWritestream)
      end
      raise ArgumentError, "Invalid arguments when calling sender(port,host)"
    end

### - (`self`) unlisten_multicast_group(multicastAddress = nil, networkInterface = nil, source = nil) { ... }

Leaves a multicast group and stops listening for packets send to it on the given network interface. The is notified once the operation completes.

Parameters:

- multicastAddress (`String`) (defaults to: `nil`) —
  the address of the multicast group to join
- networkInterface (`String`) (defaults to: `nil`) —
  the network interface on which to listen for packets.
- source (`String`) (defaults to: `nil`) —
  the address of the source for which we will listen for multicast packets

Yields:

- the handler to notify once the operation completes

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 132

    def unlisten_multicast_group(multicastAddress=nil,networkInterface=nil,source=nil)
      if multicastAddress.class == String && block_given? && networkInterface == nil && source == nil
        @j_del.java_method(:unlistenMulticastGroup, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(multicastAddress,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::DatagramSocket) : nil) }))
        return self
      elsif multicastAddress.class == String && networkInterface.class == String && source.class == String && block_given?
        @j_del.java_method(:unlistenMulticastGroup, [Java::java.lang.String.java_class,Java::java.lang.String.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(multicastAddress,networkInterface,source,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::DatagramSocket) : nil) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling unlisten_multicast_group(multicastAddress,networkInterface,source)"
    end