Top Description Methods
io.vertx.core.net

public Interface NetSocket

extends ReadStream<Buffer>, WriteStream<Buffer>
Known Direct Subinterfaces
io.vertx.core.net.impl.NetSocketInternal
Known Direct Implementers
io.vertx.core.http.impl.HttpNetSocket
Annotations
@VertxGen
Imports
io.vertx.codegen.annotations.CacheReturn, .Fluent, .GenIgnore, .Nullable, .VertxGen, io.vertx.core.AsyncResult, .Future, .Handler, io.vertx.core.buffer.Buffer, io.vertx.core.streams.ReadStream, .WriteStream, javax.net.ssl.SSLPeerUnverifiedException, .SSLSession, javax.security.cert.X509Certificate, java.security.cert.Certificate, java.util.List

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 ReadStream and WriteStream so it can be used with io.vertx.core.streams.Pipe to pipe data with flow control.

Author
Tim Fox

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the application-level protocol negotiated during the TLS handshake
applicationLayerProtocol
()

public Future<Void>

Returns:

a future completed with the result
close
()

Close the NetSocket

public void
close(Handler<AsyncResult<Void>> handler)

Close the NetSocket and notify the handler when the operation completes.

public NetSocket

Returns:

a reference to this, so the API can be used fluently
closeHandler
(@Nullable Handler<Void>
the handler
handler
)

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

public NetSocket
public Future<Void>

Returns:

a future completed with the result
end
()

Redeclares as abstract: io.vertx.core.streams.WriteStream.end.

Calls close()

public void
public NetSocket
endHandler(Handler<Void> endHandler)

This handler might be called after the close handler when the socket is paused and there are still buffers to deliver.

public NetSocket
public NetSocket
fetch(long amount)

Redeclares io.vertx.core.streams.ReadStream.fetch.

Fetch the specified amount of elements.

public NetSocket
public String

Returns:

the indicated server name
indicatedServerName
()

Returns the SNI server name presented during the SSL handshake by the client.

public boolean

Returns:

true if this io.vertx.core.net.NetSocket is encrypted via SSL/TLS.
isSsl
()

public SocketAddress

Returns:

the local address for this connection, possibly null (e.g a server bound on a domain socket) If useProxyProtocol is set to true, the address returned will be of the proxy.
localAddress
()

public SocketAddress
localAddress(boolean real)

Like localAddress() ()} but returns the server local address when real is true

public NetSocket
pause()

Redeclares io.vertx.core.streams.ReadStream.pause.

Pause the ReadStream, it sets the buffer in fetch mode and clears the actual demand.

public X509Certificate[]

Returns:

an ordered array of the peer certificates. Returns null if connection is not SSL.
peerCertificateChain
()
Deprecated instead use peerCertificates() or sslSession()

public List<Certificate>

Returns:

an ordered list of the peer certificates. Returns null if connection is not SSL.
peerCertificates
()

public SocketAddress

Returns:

the remote address for this connection, possibly null (e.g a server bound on a domain socket). If useProxyProtocol is set to true, the address returned will be of the actual connecting client.
remoteAddress
()

public SocketAddress
remoteAddress(boolean real)

Like remoteAddress() but returns the proxy remote address when real is true

public NetSocket
resume()

Redeclares io.vertx.core.streams.ReadStream.resume.

Resume reading, and sets the buffer in flowing mode.

public default Future<Void>

Returns:

a future result of the send operation
sendFile
(String
file name of the file to send
filename
)

Tell the operating system to stream a file as specified by filename directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system.

public default Future<Void>

Returns:

a future result of the send operation
sendFile
(String
file name of the file to send
filename
,
long
offset
offset
)

Tell the operating system to stream a file as specified by filename directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system.

public Future<Void>

Returns:

a future result of the send operation
sendFile
(String
file name of the file to send
filename
,
long
offset
offset
,
long
length
length
)

Tell the operating system to stream a file as specified by filename directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system.

public default NetSocket

Returns:

a reference to this, so the API can be used fluently
sendFile
(String
file name of the file to send
filename
,
Handler<AsyncResult<Void>>
handler
resultHandler
)

Same as sendFile(String) but also takes a handler that will be called when the send has completed or a failure has occurred

public default NetSocket

Returns:

a reference to this, so the API can be used fluently
sendFile
(String
file name of the file to send
filename
,
long
offset
offset
,
Handler<AsyncResult<Void>>
handler
resultHandler
)

Same as sendFile(String, long) but also takes a handler that will be called when the send has completed or a failure has occurred

public NetSocket

Returns:

a reference to this, so the API can be used fluently
sendFile
(String
file name of the file to send
filename
,
long
offset
offset
,
long
length
length
,
Handler<AsyncResult<Void>>
handler
resultHandler
)

Same as sendFile(String, long, long) but also takes a handler that will be called when the send has completed or a failure has occurred

public NetSocket
setWriteQueueMaxSize(int
the max size of the write stream
maxSize
)

Redeclares io.vertx.core.streams.WriteStream.setWriteQueueMaxSize.

Set the maximum size of the write queue to maxSize.

public SSLSession

Returns:

SSLSession associated with the underlying socket. Returns null if connection is not SSL.
sslSession
()

public NetSocket

Returns:

a reference to this, so the API can be used fluently
upgradeToSsl
(Handler<AsyncResult<Void>>
the handler will be notified when it's upgraded
handler
)

Upgrade channel to use SSL/TLS.

public Future<Void>
upgradeToSsl()

Like upgradeToSsl(Handler) but returns a Future of the asynchronous result

public NetSocket

Returns:

a reference to this, so the API can be used fluently
upgradeToSsl
(String
the server name
serverName
,
Handler<AsyncResult<Void>>
the handler will be notified when it's upgraded
handler
)

Upgrade channel to use SSL/TLS.

public Future<Void>
upgradeToSsl(String serverName)

Like upgradeToSsl(String, Handler) but returns a Future of the asynchronous result

public void
write(String str, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.streams.WriteStream.write.

Same as write(String) but with an handler called when the operation completes

public Future<Void>

Returns:

a future result of the write
write
(String
the string to write
str
)

Redeclares io.vertx.core.streams.WriteStream.write.

Write a String to the connection, encoded in UTF-8.

public void
write(String str, String enc, Handler<AsyncResult<Void>> handler)

Same as write(String, String) but with an handler called when the operation completes

public Future<Void>

Returns:

a future completed with the result
write
(String
the string to write
str
,
String
the encoding to use
enc
)

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

public void
write(Buffer message, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.streams.WriteStream.write.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Like write(Object) but with an handler called when the message has been written or failed to be written.

public String

Returns:

the write handler ID
writeHandlerID
()

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

Inherited from io.vertx.core.streams.ReadStream:
collectendHandlerexceptionHandlerhandlerpipepipeTopipeTo
Inherited from io.vertx.core.streams.WriteStream:
drainHandlerendexceptionHandlerwriteQueueFull

Method Detail

applicationLayerProtocolback to summary
public String applicationLayerProtocol()
Returns:String

the application-level protocol negotiated during the TLS handshake

closeback to summary
public Future<Void> close()

Close the NetSocket

Returns:Future<Void>

a future completed with the result

closeback to summary
public void close(Handler<AsyncResult<Void>> handler)

Close the NetSocket and notify the handler when the operation completes.

closeHandlerback to summary
public NetSocket closeHandler(@Nullable Handler<Void> handler)

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

Parameters
handler:@Nullable Handler<Void>

the handler

Returns:NetSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
drainHandlerback to summary
public NetSocket drainHandler(Handler<Void> handler)
Annotations
@Override
endback to summary
public Future<Void> end()

Redeclares as abstract: io.vertx.core.streams.WriteStream.end.

Calls close()

Returns:Future<Void>

a future completed with the result

Annotations
@Override
endback to summary
public void end(Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.streams.WriteStream.end.

Redeclares as abstract: io.vertx.core.streams.WriteStream.end.

Calls end().

Annotations
@Override
endHandlerback to summary
public NetSocket endHandler(Handler<Void> endHandler)

This handler might be called after the close handler when the socket is paused and there are still buffers to deliver.

Annotations
@Override
exceptionHandlerback to summary
public NetSocket exceptionHandler(Handler<Throwable> handler)
Annotations
@Override
fetchback to summary
public NetSocket fetch(long amount)

Redeclares io.vertx.core.streams.ReadStream.fetch.

Doc from io.vertx.core.streams.ReadStream.fetch.

Fetch the specified amount of elements. If the ReadStream has been paused, reading will recommence with the specified amount of items, otherwise the specified amount will be added to the current stream demand.

Returns:NetSocket

a reference to this, so the API can be used fluently

Annotations
@Override
handlerback to summary
public NetSocket handler(Handler<Buffer> handler)
Annotations
@Override
indicatedServerNameback to summary
public String indicatedServerName()

Returns the SNI server name presented during the SSL handshake by the client.

Returns:String

the indicated server name

isSslback to summary
public boolean isSsl()
Returns:boolean

true if this io.vertx.core.net.NetSocket is encrypted via SSL/TLS.

localAddressback to summary
public SocketAddress localAddress()
Returns:SocketAddress

the local address for this connection, possibly null (e.g a server bound on a domain socket) If useProxyProtocol is set to true, the address returned will be of the proxy.

Annotations
@CacheReturn
localAddressback to summary
public SocketAddress localAddress(boolean real)

Like localAddress() ()} but returns the server local address when real is true

pauseback to summary
public NetSocket pause()

Redeclares io.vertx.core.streams.ReadStream.pause.

Doc from io.vertx.core.streams.ReadStream.pause.

Pause the ReadStream, it sets the buffer in fetch mode and clears the actual demand.

While it's paused, no data will be sent to the data handler.

Returns:NetSocket

a reference to this, so the API can be used fluently

Annotations
@Override
peerCertificateChainback to summary
public X509Certificate[] peerCertificateChain() throws SSLPeerUnverifiedException

Deprecated

instead use peerCertificates() or sslSession()

Returns:X509Certificate[]

an ordered array of the peer certificates. Returns null if connection is not SSL.

Annotations
@Deprecated
@GenIgnore
Exceptions
SSLPeerUnverifiedException:
SSL peer's identity has not been verified.
See Also
javax.net.ssl.SSLSession#getPeerCertificateChain(), sslSession()
peerCertificatesback to summary
public List<Certificate> peerCertificates() throws SSLPeerUnverifiedException
Returns:List<Certificate>

an ordered list of the peer certificates. Returns null if connection is not SSL.

Annotations
@GenIgnore
Exceptions
SSLPeerUnverifiedException:
SSL peer's identity has not been verified.
See Also
javax.net.ssl.SSLSession#getPeerCertificateChain(), sslSession()
remoteAddressback to summary
public SocketAddress remoteAddress()
Returns:SocketAddress

the remote address for this connection, possibly null (e.g a server bound on a domain socket). If useProxyProtocol is set to true, the address returned will be of the actual connecting client.

Annotations
@CacheReturn
remoteAddressback to summary
public SocketAddress remoteAddress(boolean real)

Like remoteAddress() but returns the proxy remote address when real is true

resumeback to summary
public NetSocket resume()

Redeclares io.vertx.core.streams.ReadStream.resume.

Doc from io.vertx.core.streams.ReadStream.resume.

Resume reading, and sets the buffer in flowing mode.

If the ReadStream has been paused, reading will recommence on it.

Returns:NetSocket

a reference to this, so the API can be used fluently

Annotations
@Override
sendFileback to summary
public default Future<Void> sendFile(String filename)

Tell the operating system to stream a file as specified by filename directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system. This is a very efficient way to stream files.

Parameters
filename:String

file name of the file to send

Returns:Future<Void>

a future result of the send operation

sendFileback to summary
public default Future<Void> sendFile(String filename, long offset)

Tell the operating system to stream a file as specified by filename directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system. This is a very efficient way to stream files.

Parameters
filename:String

file name of the file to send

offset:long

offset

Returns:Future<Void>

a future result of the send operation

sendFileback to summary
public Future<Void> sendFile(String filename, long offset, long length)

Tell the operating system to stream a file as specified by filename directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system. This is a very efficient way to stream files.

Parameters
filename:String

file name of the file to send

offset:long

offset

length:long

length

Returns:Future<Void>

a future result of the send operation

sendFileback to summary
public default NetSocket sendFile(String filename, Handler<AsyncResult<Void>> resultHandler)

Same as sendFile(String) but also takes a handler that will be called when the send has completed or a failure has occurred

Parameters
filename:String

file name of the file to send

resultHandler:Handler<AsyncResult<Void>>

handler

Returns:NetSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
sendFileback to summary
public default NetSocket sendFile(String filename, long offset, Handler<AsyncResult<Void>> resultHandler)

Same as sendFile(String, long) but also takes a handler that will be called when the send has completed or a failure has occurred

Parameters
filename:String

file name of the file to send

offset:long

offset

resultHandler:Handler<AsyncResult<Void>>

handler

Returns:NetSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
sendFileback to summary
public NetSocket sendFile(String filename, long offset, long length, Handler<AsyncResult<Void>> resultHandler)

Same as sendFile(String, long, long) but also takes a handler that will be called when the send has completed or a failure has occurred

Parameters
filename:String

file name of the file to send

offset:long

offset

length:long

length

resultHandler:Handler<AsyncResult<Void>>

handler

Returns:NetSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
setWriteQueueMaxSizeback to summary
public NetSocket setWriteQueueMaxSize(int maxSize)

Redeclares io.vertx.core.streams.WriteStream.setWriteQueueMaxSize.

Doc from io.vertx.core.streams.WriteStream.setWriteQueueMaxSize.

Set the maximum size of the write queue to maxSize. You will still be able to write to the stream even if there is more than maxSize items in the write queue. This is used as an indicator by classes such as Pipe to provide flow control.

The value is defined by the implementation of the stream, e.g in bytes for a io.vertx.core.net.NetSocket, etc...

Parameters
maxSize:int

the max size of the write stream

Returns:NetSocket

a reference to this, so the API can be used fluently

Annotations
@Override
sslSessionback to summary
public SSLSession sslSession()
Returns:SSLSession

SSLSession associated with the underlying socket. Returns null if connection is not SSL.

Annotations
@GenIgnore:permitted-type
See Also
javax.net.ssl.SSLSession
upgradeToSslback to summary
public NetSocket upgradeToSsl(Handler<AsyncResult<Void>> handler)

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

Parameters
handler:Handler<AsyncResult<Void>>

the handler will be notified when it's upgraded

Returns:NetSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
upgradeToSslback to summary
public Future<Void> upgradeToSsl()

Like upgradeToSsl(Handler) but returns a Future of the asynchronous result

upgradeToSslback to summary
public NetSocket upgradeToSsl(String serverName, Handler<AsyncResult<Void>> handler)

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

Parameters
serverName:String

the server name

handler:Handler<AsyncResult<Void>>

the handler will be notified when it's upgraded

Returns:NetSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
upgradeToSslback to summary
public Future<Void> upgradeToSsl(String serverName)

Like upgradeToSsl(String, Handler) but returns a Future of the asynchronous result

writeback to summary
public void write(String str, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.streams.WriteStream.write.

Same as write(String) but with an handler called when the operation completes

writeback to summary
public Future<Void> write(String str)

Redeclares io.vertx.core.streams.WriteStream.write.

Write a String to the connection, encoded in UTF-8.

Parameters
str:String

the string to write

Returns:Future<Void>

a future result of the write

writeback to summary
public void write(String str, String enc, Handler<AsyncResult<Void>> handler)

Same as write(String, String) but with an handler called when the operation completes

writeback to summary
public Future<Void> write(String str, String enc)

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

Parameters
str:String

the string to write

enc:String

the encoding to use

Returns:Future<Void>

a future completed with the result

writeback to summary
public void write(Buffer message, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.streams.WriteStream.write.

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Like write(Object) but with an handler called when the message has been written or failed to be written.

writeHandlerIDback to summary
public String writeHandlerID()

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

By default, no handler is registered, the feature must be enabled via NetClientOptions#setRegisterWriteHandler(boolean) or NetServerOptions#setRegisterWriteHandler(boolean).

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

See Also
NetClientOptions#setRegisterWriteHandler(boolean), NetServerOptions#setRegisterWriteHandler(boolean)