Socket
interface Socket
A pair of streams for interactive communication with another machine.
Send data to the peer by writing to sink, and read data from the peer by reading from source.
This can be implemented by a plain TCP socket. It can also be layered to add features like security (as in a TLS socket) or connectivity (as in a proxy socket).
Closing the source does not impact the sink, and vice versa.
You must close the source and the sink to release the resources held by this socket. If you're using both from the same thread, you can do that with nested use blocks:
socket.source.use { source ->
socket.sink.use { sink ->
readAndWrite(source, sink)
}
}Content copied to clipboard