Class List Method List File List

# Class: Vertx::NetSocket

Inherits:
  Object
  - Object
  - Vertx::NetSocket
  show all
Includes:
  ReadStream, WriteStream
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb

## Overview

Represents a socket-like interface to a TCP connection on either the client or the server side.

Instances of this class are created on the client side by an NetClient when a connection to a server is made, or on the server side by a NetServer when a server accepts a connection.

It implements both and so it can be used with Pump to pump data with flow control.

## Constant Summary

@@j_api_type =

      Object.new

## Class Method Summary (collapse)

- + (Boolean) accept?(obj)
- + (Object) j_api_type
- + (Object) j_class
- + (Object) unwrap(obj)
- + (Object) wrap(obj)

## Instance Method Summary (collapse)

- - (void) close
  Close the NetSocket.
- - (self) close_handler { ... }
  Set a handler that will be called when the NetSocket is closed.
- - (self) drain_handler { ... }
- - (void) end(t = nil)
  Same as #end but writes some data to the stream before ending.
- - (self) end_handler { ... }
- - (self) exception_handler { ... }
- - (self) handler { ... }
- - (::Vertx::SocketAddress) local_address
  The local address for this socket.
- - (self) pause
- - (::Vertx::SocketAddress) remote_address
  The remote address for this socket.
- - (self) resume
- - (self) send_file(filename = nil, offset = nil, length = nil) { ... }
  Same as #send_file but also takes a handler that will be called when the send has completed or a failure has occurred.
- - (self) set_write_queue_max_size(maxSize = nil)
- - (true, false) ssl?
  True if this NetSocket is encrypted via SSL/TLS.
- - (self) upgrade_to_ssl { ... }
  Upgrade channel to use SSL/TLS.
- - (self) write(param_1 = nil, param_2 = nil)
  Write a String to the connection, encoded using the encoding enc.
- - (String) write_handler_id
  When a NetSocket is created it automatically registers an event handler with the event bus, the ID of that handler is given by writeHandlerID.
- - (true, false) write_queue_full
  This will return true if there are more bytes in the write queue than the value set using #set_write_queue_max_size.

## Class Method Details

### + (`Boolean`) accept?(obj)

Returns:

- (`Boolean`)

    31
    32
    33
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 31

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

### + (`Object`) j_api_type

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

    def self.j_api_type
      @@j_api_type
    end

### + (`Object`) j_class

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

    def self.j_class
      Java::IoVertxCoreNet::NetSocket.java_class
    end

### + (`Object`) unwrap(obj)

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

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

### + (`Object`) wrap(obj)

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

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

## Instance Method Details

### - (`void`) close

This method returns an undefined value.

Close the NetSocket

Raises:

- (`ArgumentError`)

    212
    213
    214
    215
    216
    217
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 212

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

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

Set a handler that will be called when the NetSocket is closed

Yields:

- the handler

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    221
    222
    223
    224
    225
    226
    227
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 221

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

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

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    141
    142
    143
    144
    145
    146
    147
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 141

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

### - (`void`) end(t = nil)

This method returns an undefined value.

Same as #end but writes some data to the stream before ending.

Parameters:

- t (`::Vertx::Buffer`) (defaults to: `nil`)

Raises:

- (`ArgumentError`)

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

    def end(t=nil)
      if !block_given? && t == nil
        return @j_del.java_method(:end, []).call()
      elsif t.class.method_defined?(:j_del) && !block_given?
        return @j_del.java_method(:end, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(t.j_del)
      end
      raise ArgumentError, "Invalid arguments when calling end(#{t})"
    end

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

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

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

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

    67
    68
    69
    70
    71
    72
    73
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 67

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

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

    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::Buffer)) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling handler()"
    end

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

Returns the local address for this socket

Returns:

- (`::Vertx::SocketAddress`) —
  the local address for this socket

Raises:

- (`ArgumentError`)

    201
    202
    203
    204
    205
    206
    207
    208
    209
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 201

    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

### - (`self`) pause

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    84
    85
    86
    87
    88
    89
    90
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 84

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

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

Returns the remote address for this socket

Returns:

- (`::Vertx::SocketAddress`) —
  the remote address for this socket

Raises:

- (`ArgumentError`)

    191
    192
    193
    194
    195
    196
    197
    198
    199
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 191

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

### - (`self`) resume

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

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

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

### - (`self`) send_file(filename = nil, offset = nil, length = nil) { ... }

Same as #send_file but also takes a handler that will be called when the send has completed or a failure has occurred

Parameters:

- filename (`String`) (defaults to: `nil`) —
  file name of the file to send
- offset (`Fixnum`) (defaults to: `nil`) —
  offset
- length (`Fixnum`) (defaults to: `nil`) —
  length

Yields:

- handler

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 168

    def send_file(filename=nil,offset=nil,length=nil)
      if filename.class == String && !block_given? && offset == nil && length == nil
        @j_del.java_method(:sendFile, [Java::java.lang.String.java_class]).call(filename)
        return self
      elsif filename.class == String && offset.class == Fixnum && !block_given? && length == nil
        @j_del.java_method(:sendFile, [Java::java.lang.String.java_class,Java::long.java_class]).call(filename,offset)
        return self
      elsif filename.class == String && block_given? && offset == nil && length == nil
        @j_del.java_method(:sendFile, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(filename,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) }))
        return self
      elsif filename.class == String && offset.class == Fixnum && length.class == Fixnum && !block_given?
        @j_del.java_method(:sendFile, [Java::java.lang.String.java_class,Java::long.java_class,Java::long.java_class]).call(filename,offset,length)
        return self
      elsif filename.class == String && offset.class == Fixnum && block_given? && length == nil
        @j_del.java_method(:sendFile, [Java::java.lang.String.java_class,Java::long.java_class,Java::IoVertxCore::Handler.java_class]).call(filename,offset,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) }))
        return self
      elsif filename.class == String && offset.class == Fixnum && length.class == Fixnum && block_given?
        @j_del.java_method(:sendFile, [Java::java.lang.String.java_class,Java::long.java_class,Java::long.java_class,Java::IoVertxCore::Handler.java_class]).call(filename,offset,length,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling send_file(#{filename},#{offset},#{length})"
    end

### - (`self`) set_write_queue_max_size(maxSize = nil)

Parameters:

- maxSize (`Fixnum`) (defaults to: `nil`)

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

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

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

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

Returns true if this Vertx::NetSocket is encrypted via SSL/TLS.

Returns:

- (`true`, `false`) —
  true if this Vertx::NetSocket is encrypted via SSL/TLS.

Raises:

- (`ArgumentError`)

    239
    240
    241
    242
    243
    244
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 239

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

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

Upgrade channel to use SSL/TLS. Be aware that for this to work SSL must be configured.

Yields:

- the handler will be notified when it's upgraded

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    231
    232
    233
    234
    235
    236
    237
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 231

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

### - (`self`) write(data) - (`self`) write(str) - (`self`) write(str, enc)

Write a String to the connection, encoded using the encoding `enc`.

Overloads:

- - (`self`) write(data)

  Parameters:

  - data (`::Vertx::Buffer`)
- - (`self`) write(str)

  Parameters:

  - str (`String`) —
    the string to write
- - (`self`) write(str, enc)

  Parameters:

  - str (`String`) —
    the string to write
  - enc (`String`) —
    the encoding to use

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 117

    def write(param_1=nil,param_2=nil)
      if param_1.class.method_defined?(:j_del) && !block_given? && param_2 == nil
        @j_del.java_method(:write, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(param_1.j_del)
        return self
      elsif param_1.class == String && !block_given? && param_2 == nil
        @j_del.java_method(:write, [Java::java.lang.String.java_class]).call(param_1)
        return self
      elsif param_1.class == String && param_2.class == String && !block_given?
        @j_del.java_method(:write, [Java::java.lang.String.java_class,Java::java.lang.String.java_class]).call(param_1,param_2)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling write(#{param_1},#{param_2})"
    end

### - (`String`) write_handler_id

When a `NetSocket` is created it automatically registers an event handler with the event bus, the ID of that handler is given by `writeHandlerID`.

Given this ID, a different event loop can send a buffer to that event handler using the event bus and that buffer will be received by this instance in its own event loop and written to the underlying connection. This allows you to write data to other connections which are owned by different event loops.

Returns:

- (`String`) —
  the write handler ID

Raises:

- (`ArgumentError`)

    155
    156
    157
    158
    159
    160
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 155

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

### - (`true`, `false`) write_queue_full

This will return `true` if there are more bytes in the write queue than the value set using #set_write_queue_max_size

Returns:

- (`true`, `false`) —
  true if write queue is full

Raises:

- (`ArgumentError`)

    59
    60
    61
    62
    63
    64
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/net_socket.rb', line 59

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