public interface NetSocket extends ReadStream<NetSocket>, WriteStream<NetSocket>
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
Pump
to pump data with flow control.
Instances of this class are not thread-safe.
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the NetSocket
|
NetSocket |
closeHandler(Handler<java.lang.Void> handler)
Set a handler that will be called when the NetSocket is closed
|
boolean |
isSsl()
Returns
true if this NetSocket is encrypted via SSL/TLS. |
java.net.InetSocketAddress |
localAddress()
Return the local address for this socket
|
java.net.InetSocketAddress |
remoteAddress()
Return the remote address for this socket
|
NetSocket |
sendFile(java.lang.String filename)
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. |
NetSocket |
sendFile(java.lang.String filename,
Handler<AsyncResult<java.lang.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 |
NetSocket |
ssl(Handler<java.lang.Void> handler)
Upgrade channel to use SSL/TLS.
|
NetSocket |
write(Buffer data)
Write a
Buffer to the request body. |
NetSocket |
write(java.lang.String str)
Write a
String to the connection, encoded in UTF-8. |
NetSocket |
write(java.lang.String str,
java.lang.String enc)
Write a
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 . |
endHandler
dataHandler, pause, resume
exceptionHandler
drainHandler, setWriteQueueMaxSize, writeQueueFull
java.lang.String writeHandlerID()
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.
NetSocket write(Buffer data)
Buffer
to the request body.write
in interface WriteStream<NetSocket>
NetSocket write(java.lang.String str)
String
to the connection, encoded in UTF-8.NetSocket write(java.lang.String str, java.lang.String enc)
String
to the connection, encoded using the encoding enc
.NetSocket sendFile(java.lang.String filename)
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.NetSocket sendFile(java.lang.String filename, Handler<AsyncResult<java.lang.Void>> resultHandler)
sendFile(String)
but also takes a handler that will be called when the send has completed or
a failure has occurredjava.net.InetSocketAddress remoteAddress()
java.net.InetSocketAddress localAddress()
void close()
NetSocket closeHandler(Handler<java.lang.Void> handler)
NetSocket ssl(Handler<java.lang.Void> handler)
boolean isSsl()
true
if this NetSocket
is encrypted via SSL/TLS.