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)

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

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

+ (Object) j_api_type


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

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class


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

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

+ (Object) unwrap(obj)


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

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

+ (Object) wrap(obj)


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

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)

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

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)

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

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)

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

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)

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

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) fetch(amount = nil)

Parameters:

  • amount (Fixnum) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)

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

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)

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

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)

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

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)

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

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:

Raises:

  • (ArgumentError)

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

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)

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

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)

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

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)

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

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)

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

def pipe_to(dst=nil)
  if dst.class.method_defined?(:j_del) && !block_given?
    return @j_del.java_method(:pipeTo, [Java::IoVertxCoreStreams::WriteStream.java_class]).call(dst.j_del)
  elsif dst.class.method_defined?(:j_del) && block_given?
    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) }))
  end
  raise ArgumentError, "Invalid arguments when calling pipe_to(#{dst})"
end

- (self) resume

Returns:

  • (self)

Raises:

  • (ArgumentError)

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

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)

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

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::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)

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

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)

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

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