Top Description Methods
io.vertx.core.net

public Interface NetServer

extends Measured
Known Direct Implementers
io.vertx.core.net.impl.NetServerImpl
Annotations
@VertxGen
Imports
io.vertx.codegen.annotations.GenIgnore, .Nullable, .Fluent, .VertxGen, io.vertx.core.AsyncResult, .Future, .Handler, io.vertx.core.metrics.Measured, io.vertx.core.net.impl.SocketAddressImpl, io.vertx.core.streams.ReadStream

Represents a TCP server
Author
Tim Fox

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the actual port the server is listening on.
actualPort
()

The actual port the server is listening on.

public Future<Void>

Returns:

a future completed with the listen operation result
close
()

Close the server.

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

Like close but supplying a handler that will be notified when close is complete.

public NetServer

Returns:

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

Supply a connect handler for this server.

public Handler<NetSocket>
public ReadStream<NetSocket>

Returns:

the connect stream
connectStream
()
Deprecated instead use connectHandler(Handler)

Return the connect stream for this server.

public NetServer

Returns:

a reference to this, so the API can be used fluently
exceptionHandler
(Handler<Throwable>
the handler to set
handler
)

Set an exception handler called for socket errors happening before the connection is passed to the connectHandler, e.g during the TLS handshake.

public Future<NetServer>

Returns:

a future completed with the listen operation result
listen
()

Start listening on the port and host as configured in the io.vertx.core.net.NetServerOptions used when creating the server.

public default NetServer

Returns:

a reference to this, so the API can be used fluently
listen
(Handler<AsyncResult<NetServer>>
handler that will be notified when listening or failed
listenHandler
)

Like listen but providing a handler that will be notified when the server is listening, or fails.

public default Future<NetServer>

Returns:

a future completed with the listen operation result
listen
(int port, String host)

Start listening on the specified port and host, ignoring port and host configured in the io.vertx.core.net.NetServerOptions used when creating the server.

public default NetServer

Returns:

a reference to this, so the API can be used fluently
listen
(int
the port to listen on
port
,
String
the host to listen on
host
,
Handler<AsyncResult<NetServer>>
handler that will be notified when listening or failed
listenHandler
)

Like listen(int, String) but providing a handler that will be notified when the server is listening, or fails.

public default Future<NetServer>

Returns:

a future completed with the listen operation result
listen
(int port)

Start listening on the specified port and host "0.0.0.0", ignoring port and host configured in the io.vertx.core.net.NetServerOptions used when creating the server.

public default NetServer

Returns:

a reference to this, so the API can be used fluently
listen
(int
the port to listen on
port
,
Handler<AsyncResult<NetServer>>
handler that will be notified when listening or failed
listenHandler
)

Like listen(int) but providing a handler that will be notified when the server is listening, or fails.

public Future<NetServer>

Returns:

a future completed with the listen operation result
listen
(SocketAddress
the local address to listen on
localAddress
)

Start listening on the specified local address, ignoring port and host configured in the io.vertx.core.net.NetServerOptions used when creating the server.

public default NetServer

Returns:

a reference to this, so the API can be used fluently
listen
(SocketAddress
the local address to listen on
localAddress
,
Handler<AsyncResult<NetServer>>
handler that will be notified when listening or failed
listenHandler
)

Like listen(SocketAddress) but providing a handler that will be notified when the server is listening, or fails.

public default Future<Boolean>

Returns:

a future signaling the update success
updateSSLOptions
(SSLOptions
the new SSL options
options
)

Update the server with new SSL options, the update happens if the options object is valid and different from the existing options object.

public default void
updateSSLOptions(SSLOptions
the new SSL options
options
,
Handler<AsyncResult<Boolean>>
the update handler
handler
)

Like updateSSLOptions(SSLOptions) but supplying a handler that will be called when the update happened (or has failed).

public Future<Boolean>

Returns:

a future signaling the update success
updateSSLOptions
(SSLOptions
the new SSL options
options
,
boolean
force the update when options are equals
force
)

Update the server with new SSL options, the update happens if the options object is valid and different from the existing options object.

public default void
updateSSLOptions(SSLOptions
the new SSL options
options
,
boolean
force the update when options are equals
force
,
Handler<AsyncResult<Boolean>>
the update handler
handler
)

Like updateSSLOptions(SSLOptions) but supplying a handler that will be called when the update happened (or has failed).

public void
updateTrafficShapingOptions(TrafficShapingOptions
the new traffic shaping options
options
)

Update traffic shaping options options, the update happens if valid values are passed for traffic shaping options.

Inherited from io.vertx.core.metrics.Measured:
isMetricsEnabled

Method Detail

actualPortback to summary
public int actualPort()

The actual port the server is listening on. This is useful if you bound the server specifying 0 as port number signifying an ephemeral port

Returns:int

the actual port the server is listening on.

closeback to summary
public Future<Void> close()

Close the server. This will close any currently open connections. The close may not complete until after this method has returned.

Returns:Future<Void>

a future completed with the listen operation result

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

Like close but supplying a handler that will be notified when close is complete.

Parameters
completionHandler:Handler<AsyncResult<Void>>

the handler

connectHandlerback to summary
public NetServer connectHandler(@Nullable Handler<NetSocket> handler)

Supply a connect handler for this server. The server can only have at most one connect handler at any one time. As the server accepts TCP or SSL connections it creates an instance of NetSocket and passes it to the connect handler.

Returns:NetServer

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

connectHandlerback to summary
public Handler<NetSocket> connectHandler()
Annotations
@GenIgnore
connectStreamback to summary
public ReadStream<NetSocket> connectStream()

Deprecated

instead use connectHandler(Handler)

Return the connect stream for this server. The server can only have at most one handler at any one time. As the server accepts TCP or SSL connections it creates an instance of NetSocket and passes it to the connect stream ReadStream#handler(io.vertx.core.Handler).

Returns:ReadStream<NetSocket>

the connect stream

Annotations
@Deprecated
exceptionHandlerback to summary
public NetServer exceptionHandler(Handler<Throwable> handler)

Set an exception handler called for socket errors happening before the connection is passed to the connectHandler, e.g during the TLS handshake.

Parameters
handler:Handler<Throwable>

the handler to set

Returns:NetServer

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

Annotations
@GenIgnore
@Fluent
listenback to summary
public Future<NetServer> listen()

Start listening on the port and host as configured in the io.vertx.core.net.NetServerOptions used when creating the server.

The server may not be listening until some time after the call to listen has returned.

Returns:Future<NetServer>

a future completed with the listen operation result

listenback to summary
public default NetServer listen(Handler<AsyncResult<NetServer>> listenHandler)

Like listen but providing a handler that will be notified when the server is listening, or fails.

Parameters
listenHandler:Handler<AsyncResult<NetServer>>

handler that will be notified when listening or failed

Returns:NetServer

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

Annotations
@Fluent
listenback to summary
public default Future<NetServer> listen(int port, String host)

Start listening on the specified port and host, ignoring port and host configured in the io.vertx.core.net.NetServerOptions used when creating the server.

Port 0 can be specified meaning "choose an random port".

Host 0.0.0.0 can be specified meaning "listen on all available interfaces".

The server may not be listening until some time after the call to listen has returned.

Returns:Future<NetServer>

a future completed with the listen operation result

listenback to summary
public default NetServer listen(int port, String host, Handler<AsyncResult<NetServer>> listenHandler)

Like listen(int, String) but providing a handler that will be notified when the server is listening, or fails.

Parameters
port:int

the port to listen on

host:String

the host to listen on

listenHandler:Handler<AsyncResult<NetServer>>

handler that will be notified when listening or failed

Returns:NetServer

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

Annotations
@Fluent
listenback to summary
public default Future<NetServer> listen(int port)

Start listening on the specified port and host "0.0.0.0", ignoring port and host configured in the io.vertx.core.net.NetServerOptions used when creating the server.

Port 0 can be specified meaning "choose an random port".

The server may not be listening until some time after the call to listen has returned.

Returns:Future<NetServer>

a future completed with the listen operation result

listenback to summary
public default NetServer listen(int port, Handler<AsyncResult<NetServer>> listenHandler)

Like listen(int) but providing a handler that will be notified when the server is listening, or fails.

Parameters
port:int

the port to listen on

listenHandler:Handler<AsyncResult<NetServer>>

handler that will be notified when listening or failed

Returns:NetServer

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

Annotations
@Fluent
listenback to summary
public Future<NetServer> listen(SocketAddress localAddress)

Start listening on the specified local address, ignoring port and host configured in the io.vertx.core.net.NetServerOptions used when creating the server.

The server may not be listening until some time after the call to listen has returned.

Parameters
localAddress:SocketAddress

the local address to listen on

Returns:Future<NetServer>

a future completed with the listen operation result

listenback to summary
public default NetServer listen(SocketAddress localAddress, Handler<AsyncResult<NetServer>> listenHandler)

Like listen(SocketAddress) but providing a handler that will be notified when the server is listening, or fails.

Parameters
localAddress:SocketAddress

the local address to listen on

listenHandler:Handler<AsyncResult<NetServer>>

handler that will be notified when listening or failed

Returns:NetServer

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

Annotations
@Fluent
updateSSLOptionsback to summary
public default Future<Boolean> updateSSLOptions(SSLOptions options)

Update the server with new SSL options, the update happens if the options object is valid and different from the existing options object.

The boolean succeeded future result indicates whether the update occurred.

Parameters
options:SSLOptions

the new SSL options

Returns:Future<Boolean>

a future signaling the update success

updateSSLOptionsback to summary
public default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler)

Like updateSSLOptions(SSLOptions) but supplying a handler that will be called when the update happened (or has failed).

Parameters
options:SSLOptions

the new SSL options

handler:Handler<AsyncResult<Boolean>>

the update handler

updateSSLOptionsback to summary
public Future<Boolean> updateSSLOptions(SSLOptions options, boolean force)

Update the server with new SSL options, the update happens if the options object is valid and different from the existing options object.

The options object is compared using its equals method against the existing options to prevent an update when the objects are equals since loading options can be costly, this can happen for share TCP servers. When object are equals, setting force to true forces the update.

The boolean succeeded future result indicates whether the update occurred.

Parameters
options:SSLOptions

the new SSL options

force:boolean

force the update when options are equals

Returns:Future<Boolean>

a future signaling the update success

updateSSLOptionsback to summary
public default void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler)

Like updateSSLOptions(SSLOptions) but supplying a handler that will be called when the update happened (or has failed).

Parameters
options:SSLOptions

the new SSL options

force:boolean

force the update when options are equals

handler:Handler<AsyncResult<Boolean>>

the update handler

updateTrafficShapingOptionsback to summary
public void updateTrafficShapingOptions(TrafficShapingOptions options)

Update traffic shaping options options, the update happens if valid values are passed for traffic shaping options. This update happens synchronously and at best effort for rate update to take effect immediately.

Parameters
options:TrafficShapingOptions

the new traffic shaping options