new NetSocket()
A socket-like interface to a TCP/SSL connection on either the client or the server side.
Instances of this class are created on the client side by a
module:vertx/net.NetClient
when a connection to a server is
made, or on the server side by a vertx/net.NetServer
when a server accepts a connection.
It implements both ReadStream
and
WriteStream
so it can be used with
module:vertx/pump~Pump
to pump data with flow control.
- Source:
Extends
Methods
-
close()
-
Close this socket.
- Source:
-
closeHandler(handler)
-
Set a
Handler
to be called when this socket is closedParameters:
Name Type Description handler
Handler The close handler to use - Source:
-
dataHandler(handler)
-
Set a data handler. As data is read, the handler will be called with a Buffer containing the data read.
Parameters:
Name Type Description handler
BodyHandler the handler to call - Inherited From:
- Source:
-
drainHandler(handler)
-
Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue has been reduced to maxSize/2. See
module:vertx/pump~Pump
for an example of this being used.Parameters:
Name Type Description handler
Handler the handler to call when the stream has been drained - Inherited From:
- Source:
-
endHandler(handler)
-
Set an end handler. Once the stream has ended, and there is no more data to be read, the handler will be called.
Parameters:
Name Type Description handler
Handler the handler to call - Inherited From:
- Source:
-
exceptionHandler(handler)
-
Set an exception handler.
Parameters:
Name Type Description handler
Handler the handler to call - Inherited From:
- Source:
-
exceptionHandler(handler)
-
Set an exception handler on the stream
Parameters:
Name Type Description handler
Handler the handler to call when an exception occurs - Inherited From:
- Source:
-
isSSL()
-
Returns true if this socket is SSL/TLS encrypted.
- Source:
-
localAddress() → {Address}
-
Returns the local address for this socket
- Source:
Returns:
The local address- Type
- Address
-
pause()
-
Pause the
ReadStream
. While the stream is paused, no data will be sent to the data Handler- Inherited From:
- Source:
-
remoteAddress() → {Address}
-
Returns the remote address for this socket
- Source:
Returns:
The remote address- Type
- Address
-
resume()
-
Resume reading. If the
ReadStream
has been paused, reading will recommence on it.- Inherited From:
- Source:
-
sendFile(filename, callback) → {module:vertx/net.NetSocket}
-
Tell the kernel 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 filesParameters:
Name Type Argument Description filename
string The path to the file callback
function <optional>
A function to be called when the send has completed or a failure has occurred. - Source:
Returns:
this -
ssl(handler) → {module:vertx/net.NetSocket}
-
Upgrade channel to use SSL/TLS. Be aware that for this to work SSL must already be configured.
Parameters:
Name Type Argument Description handler
Handler <optional>
Called when the upgrade has been completed - Source:
Returns:
thisExample
var server = vertx.createNetServer(). .keyStorePath('/path/to/your/keystore/server-keystore.jks') .keyStorePassword('password'); server.connectHandler(function(sock) { if (authCheck()) { sock.ssl(); } }
-
write(chunk, encoding) → {module:vertx/net.NetSocket}
-
Write a string or
module:vertx/buffer~Buffer
to the socket.Parameters:
Name Type Argument Description chunk
string | module:vertx/buffer~Buffer the data to write encoding
string <optional>
the charset for the data (default: UTF-8) - Source:
Returns:
this -
writeHandlerID()
-
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.
- Source:
-
writeQueueFull()
-
This will return
true
if there are more bytes in the write queue than the value set usingwriteQueueMaxSize
- Inherited From:
- Source:
-
writeQueueMaxSize(size)
-
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 thanmaxSize
bytes in the write queue. This is used as an indicator by classes such asPump
to provide flow control.Parameters:
Name Type Description size
number the size of the write queue - Inherited From:
- Source: