Class: Vertx::DatagramSocket

Inherits:
Object
  • Object
show all
Includes:
Measured, ReadStream
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/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.

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


36
37
38
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 36

def @@j_api_type.accept?(obj)
  obj.class == DatagramSocket
end

+ (Object) j_api_type



45
46
47
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 45

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



48
49
50
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 48

def self.j_class
  Java::IoVertxCoreDatagram::DatagramSocket.java_class
end

+ (Object) unwrap(obj)



42
43
44
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 42

def @@j_api_type.unwrap(obj)
  obj.j_del
end

+ (Object) wrap(obj)



39
40
41
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 39

def @@j_api_type.wrap(obj)
  DatagramSocket.new(obj)
end

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)


190
191
192
193
194
195
196
197
198
199
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 190

def block_multicast_group(multicastAddress=nil,networkInterface=nil,sourceToBlock=nil)
  if multicastAddress.class == String && networkInterface.class == String && true && 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) } unless !block_given?))
    return self
  elsif multicastAddress.class == String && networkInterface.class == String && sourceToBlock.class == String && true
    @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) } unless !block_given?))
    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)


131
132
133
134
135
136
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 131

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

- (self) end_handler { ... }

Yields:

Returns:

  • (self)

Raises:

  • (ArgumentError)


239
240
241
242
243
244
245
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 239

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

- (self) exception_handler { ... }

Yields:

Returns:

  • (self)

Raises:

  • (ArgumentError)


257
258
259
260
261
262
263
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 257

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

- (self) fetch(amount = nil)

Parameters:

  • amount (Fixnum) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)


230
231
232
233
234
235
236
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 230

def fetch(amount=nil)
  if amount.class == Fixnum && !block_given?
    @j_del.java_method(:fetch, [Java::long.java_class]).call(amount)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling fetch(#{amount})"
end

- (self) handler { ... }

Yields:

Returns:

  • (self)

Raises:

  • (ArgumentError)


248
249
250
251
252
253
254
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 248

def handler
  if true
    @j_del.java_method(:handler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::DatagramPacket)) unless !block_given? }))
    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)


205
206
207
208
209
210
211
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 205

def listen(port=nil,host=nil)
  if port.class == Fixnum && host.class == String && true
    @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) } unless !block_given?))
    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)


156
157
158
159
160
161
162
163
164
165
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 156

def listen_multicast_group(multicastAddress=nil,networkInterface=nil,source=nil)
  if multicastAddress.class == String && true && 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) } unless !block_given?))
    return self
  elsif multicastAddress.class == String && networkInterface.class == String && source.class == String && true
    @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) } unless !block_given?))
    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:

Raises:

  • (ArgumentError)


140
141
142
143
144
145
146
147
148
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 140

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 metrics are enabled

Raises:

  • (ArgumentError)


53
54
55
56
57
58
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 53

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)


213
214
215
216
217
218
219
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 213

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

- (::Vertx::Pipe) pipe

Pause this stream and return a to transfer the elements of this stream to a destination .

The stream will be resumed when the pipe will be wired to a WriteStream.

Returns:

Raises:

  • (ArgumentError)


63
64
65
66
67
68
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 63

def pipe
  if !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:pipe, []).call(),::Vertx::Pipe,::Vertx::DatagramPacket.j_api_type)
  end
  raise ArgumentError, "Invalid arguments when calling pipe()"
end

- (void) pipe_to(dst = nil) { ... }

This method returns an undefined value.

Pipe this ReadStream to the WriteStream.

Elements emitted by this stream will be written to the write stream until this stream ends or fails.

Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

Parameters:

Yields:

Raises:

  • (ArgumentError)


78
79
80
81
82
83
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 78

def pipe_to(dst=nil)
  if dst.class.method_defined?(:j_del) && true
    return @j_del.java_method(:pipeTo, [Java::IoVertxCoreStreams::WriteStream.java_class,Java::IoVertxCore::Handler.java_class]).call(dst.j_del,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) } unless !block_given?))
  end
  raise ArgumentError, "Invalid arguments when calling pipe_to(#{dst})"
end

- (self) resume

Returns:

  • (self)

Raises:

  • (ArgumentError)


221
222
223
224
225
226
227
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 221

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)


103
104
105
106
107
108
109
110
111
112
113
114
115
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 103

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 && true && 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) } unless !block_given?))
    return self
  elsif param_1.class == String && param_2.class == Fixnum && param_3.class == String && true && 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) } unless !block_given?))
    return self
  elsif param_1.class == String && param_2.class == String && param_3.class == Fixnum && param_4.class == String && true
    @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) } unless !block_given?))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling send(#{param_1},#{param_2},#{param_3},#{param_4})"
end

- (::Vertx::WriteStream) sender(port = nil, host = nil)

Returns a WriteStream 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:

Raises:

  • (ArgumentError)


121
122
123
124
125
126
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 121

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::WriteStreamImpl,::Vertx::Buffer.j_api_type)
  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)


173
174
175
176
177
178
179
180
181
182
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/datagram_socket.rb', line 173

def unlisten_multicast_group(multicastAddress=nil,networkInterface=nil,source=nil)
  if multicastAddress.class == String && true && 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) } unless !block_given?))
    return self
  elsif multicastAddress.class == String && networkInterface.class == String && source.class == String && true
    @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) } unless !block_given?))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling unlisten_multicast_group(#{multicastAddress},#{networkInterface},#{source})"
end