LocalSocket  |  API reference  |  Android Developers (original) (raw)


open class LocalSocket : Closeable

Creates a (non-server) socket in the UNIX-domain namespace. The interface here is not entirely unlike that of java.net.Socket. This class and the streams returned from it may be used from multiple threads.

Summary

Constants
static Int SOCKET_DGRAM Datagram socket type
static Int SOCKET_SEQPACKET Sequential packet socket type
static Int SOCKET_STREAM Stream socket type
Public constructors
LocalSocket() Creates a AF_LOCAL/UNIX domain stream socket.
LocalSocket(sockType: Int) Creates a AF_LOCAL/UNIX domain socket with the given socket type.
Public methods
open Unit bind(bindpoint: LocalSocketAddress!) Binds this socket to an endpoint name.
open Unit close() Closes the socket.
open Unit connect(endpoint: LocalSocketAddress!) Connects this socket to an endpoint.
open Unit connect(endpoint: LocalSocketAddress!, timeout: Int)
open Array<FileDescriptor!>! getAncillaryFileDescriptors() Retrieves a set of file descriptors that a peer has sent through an ancillary message.
open FileDescriptor! getFileDescriptor() Returns file descriptor or null if not yet open/already closed
open InputStream! getInputStream() Retrieves the input stream for this instance.
open LocalSocketAddress! getLocalSocketAddress() Retrieves the name that this socket is bound to, if any.
open OutputStream! getOutputStream() Retrieves the output stream for this instance.
open Credentials! getPeerCredentials() Retrieves the credentials of this socket's peer.
open Int getReceiveBufferSize()
open LocalSocketAddress! getRemoteSocketAddress()
open Int getSendBufferSize()
open Int getSoTimeout()
open Boolean isBound()
open Boolean isClosed()
open Boolean isConnected()
open Boolean isInputShutdown()
open Boolean isOutputShutdown()
open Unit setFileDescriptorsForSend(fds: Array<FileDescriptor!>!) Enqueues a set of file descriptors to send to the peer.
open Unit setReceiveBufferSize(size: Int)
open Unit setSendBufferSize(n: Int)
open Unit setSoTimeout(n: Int)
open Unit shutdownInput() Shuts down the input side of the socket.
open Unit shutdownOutput() Shuts down the output side of the socket.
open String toString() Returns a string representation of the object.

Constants

SOCKET_DGRAM

static val SOCKET_DGRAM: Int

Datagram socket type

Value: 1

SOCKET_SEQPACKET

static val SOCKET_SEQPACKET: Int

Sequential packet socket type

Value: 3

SOCKET_STREAM

static val SOCKET_STREAM: Int

Stream socket type

Value: 2

Public constructors

LocalSocket

LocalSocket()

Creates a AF_LOCAL/UNIX domain stream socket.

LocalSocket

LocalSocket(sockType: Int)

Creates a AF_LOCAL/UNIX domain socket with the given socket type.

Parameters
sockType Int: either SOCKET_DGRAM, SOCKET_STREAM or SOCKET_SEQPACKET

Public methods

bind

open fun bind(bindpoint: LocalSocketAddress!): Unit

Binds this socket to an endpoint name. May only be called on an instance that has not yet been bound.

Parameters
bindpoint LocalSocketAddress!: endpoint address
Exceptions
java.io.IOException

close

open fun close(): Unit

Closes the socket.

Exceptions
java.lang.Exception if this resource cannot be closed
java.io.IOException

connect

open fun connect(endpoint: LocalSocketAddress!): Unit

Connects this socket to an endpoint. May only be called on an instance that has not yet been connected.

Parameters
endpoint LocalSocketAddress!: endpoint address
Exceptions
java.io.IOException if socket is in invalid state or the address does not exist.

getAncillaryFileDescriptors

open fun getAncillaryFileDescriptors(): Array<FileDescriptor!>!

Retrieves a set of file descriptors that a peer has sent through an ancillary message. This method retrieves the most recent set sent, and then returns null until a new set arrives. File descriptors may only be passed along with regular data, so this method can only return a non-null after a read operation.

Return
Array<FileDescriptor!>! null or file descriptor array
Exceptions
java.io.IOException

getFileDescriptor

open fun getFileDescriptor(): FileDescriptor!

Returns file descriptor or null if not yet open/already closed

Return
FileDescriptor! fd or null

getInputStream

open fun getInputStream(): InputStream!

Retrieves the input stream for this instance. Closing this stream is equivalent to closing the entire socket and its associated streams using #close().

Return
InputStream! input stream
Exceptions
java.io.IOException if socket has been closed or cannot be created.

getLocalSocketAddress

open fun getLocalSocketAddress(): LocalSocketAddress!

Retrieves the name that this socket is bound to, if any.

Return
LocalSocketAddress! Local address or null if anonymous

getOutputStream

open fun getOutputStream(): OutputStream!

Retrieves the output stream for this instance. Closing this stream is equivalent to closing the entire socket and its associated streams using #close().

Return
OutputStream! output stream
Exceptions
java.io.IOException if socket has been closed or cannot be created.

getPeerCredentials

open fun getPeerCredentials(): Credentials!

Retrieves the credentials of this socket's peer. Only valid on connected sockets.

Return
Credentials! non-null; peer credentials
Exceptions
java.io.IOException

getReceiveBufferSize

open fun getReceiveBufferSize(): Int

getSendBufferSize

open fun getSendBufferSize(): Int

getSoTimeout

open fun getSoTimeout(): Int

isBound

open fun isBound(): Boolean

isClosed

open fun isClosed(): Boolean

isConnected

open fun isConnected(): Boolean

isInputShutdown

open fun isInputShutdown(): Boolean

isOutputShutdown

open fun isOutputShutdown(): Boolean

setFileDescriptorsForSend

open fun setFileDescriptorsForSend(fds: Array<FileDescriptor!>!): Unit

Enqueues a set of file descriptors to send to the peer. The queue is one deep. The file descriptors will be sent with the next write of normal data, and will be delivered in a single ancillary message. See "man 7 unix" SCM_RIGHTS on a desktop Linux machine.

Parameters
fds Array<FileDescriptor!>!: non-null; file descriptors to send.

setReceiveBufferSize

open fun setReceiveBufferSize(size: Int): Unit

setSendBufferSize

open fun setSendBufferSize(n: Int): Unit

setSoTimeout

open fun setSoTimeout(n: Int): Unit

shutdownInput

open fun shutdownInput(): Unit

Shuts down the input side of the socket.

Exceptions
java.io.IOException

shutdownOutput

open fun shutdownOutput(): Unit

Shuts down the output side of the socket.

Exceptions
java.io.IOException

toString

open fun toString(): String

Returns a string representation of the object.

Return
String a string representation of the object.