Class: Vertx::DatagramSocket

Inherits:
Object
  • Object
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.

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


34
35
36
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 34

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

+ (Object) j_api_type



43
44
45
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 43

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



46
47
48
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 46

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

+ (Object) unwrap(obj)



40
41
42
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 40

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

+ (Object) wrap(obj)



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

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)


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

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)


104
105
106
107
108
109
110
111
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 104

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)


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

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)


223
224
225
226
227
228
229
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 223

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)


214
215
216
217
218
219
220
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 214

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)


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

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)


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

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)


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

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)


51
52
53
54
55
56
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 51

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)


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

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)


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

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)


76
77
78
79
80
81
82
83
84
85
86
87
88
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 76

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)


94
95
96
97
98
99
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/datagram_socket.rb', line 94

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)


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

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