@groovy.transform.CompileStatic class NetSocket extends java.lang.Object
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.
Constructor and description |
---|
NetSocket
(java.lang.Object delegate) |
Type | Name and description |
---|---|
void |
close() Close the NetSocket |
NetSocket |
closeHandler(io.vertx.core.Handler<java.lang.Void> handler) Set a handler that will be called when the NetSocket is closed |
NetSocket |
drainHandler(io.vertx.core.Handler<java.lang.Void> handler) |
void |
end(Buffer t) Same as NetSocket.end but writes some data to the stream before ending. |
void |
end() Calls NetSocket.close |
NetSocket |
endHandler(io.vertx.core.Handler<java.lang.Void> endHandler) |
NetSocket |
exceptionHandler(io.vertx.core.Handler<java.lang.Throwable> handler) |
java.lang.Object |
getDelegate() |
NetSocket |
handler(io.vertx.core.Handler<Buffer> handler) |
boolean |
isSsl()
|
SocketAddress |
localAddress() @return
|
NetSocket |
pause() |
SocketAddress |
remoteAddress() @return
|
NetSocket |
resume() |
NetSocket |
sendFile(java.lang.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. |
NetSocket |
sendFile(java.lang.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. |
NetSocket |
sendFile(java.lang.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. |
NetSocket |
sendFile(java.lang.String filename, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler) Same as NetSocket.sendFile but also takes a handler that will be called when the send has completed or a failure has occurred |
NetSocket |
sendFile(java.lang.String filename, long offset, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler) Same as NetSocket.sendFile but also takes a handler that will be called when the send has completed or a failure has occurred |
NetSocket |
sendFile(java.lang.String filename, long offset, long length, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler) Same as NetSocket.sendFile but also takes a handler that will be called when the send has completed or a failure has occurred |
NetSocket |
setWriteQueueMaxSize(int maxSize) |
NetSocket |
upgradeToSsl(io.vertx.core.Handler<java.lang.Void> handler) Upgrade channel to use SSL/TLS. |
NetSocket |
write(Buffer data) |
NetSocket |
write(java.lang.String str) Write a java.lang.String to the connection, encoded in UTF-8. |
NetSocket |
write(java.lang.String str, java.lang.String enc) Write a java.lang.String to the connection, encoded using the encoding enc . |
java.lang.String |
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 . |
boolean |
writeQueueFull() This will return true if there are more bytes in the write queue than the value set using NetSocket.setWriteQueueMaxSize |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Close the NetSocket
Set a handler that will be called when the NetSocket is closed
handler
- the handlerSame as NetSocket.end but writes some data to the stream before ending.
Calls NetSocket.close
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.
filename
- file name of the file to send 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.
filename
- file name of the file to sendoffset
- 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.
filename
- file name of the file to sendoffset
- offsetlength
- lengthSame as NetSocket.sendFile but also takes a handler that will be called when the send has completed or a failure has occurred
filename
- file name of the file to sendresultHandler
- handlerSame as NetSocket.sendFile but also takes a handler that will be called when the send has completed or a failure has occurred
filename
- file name of the file to sendoffset
- offsetresultHandler
- handlerSame as NetSocket.sendFile but also takes a handler that will be called when the send has completed or a failure has occurred
filename
- file name of the file to sendoffset
- offsetlength
- lengthresultHandler
- handlerUpgrade channel to use SSL/TLS. Be aware that for this to work SSL must be configured.
handler
- the handler will be notified when it's upgradedWrite a java.lang.String to the connection, encoded in UTF-8.
str
- the string to write Write a java.lang.String to the connection, encoded using the encoding enc
.
str
- the string to writeenc
- the encoding to use 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.
This will return true
if there are more bytes in the write queue than the value set using NetSocket.setWriteQueueMaxSize