Added in API level 1

LocalSocket


open class LocalSocket : Closeable
kotlin.Any
   ↳ android.net.LocalSocket

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

Datagram socket type

static Int

Sequential packet socket type

static Int

Stream socket type

Public constructors

Creates a AF_LOCAL/UNIX domain stream socket.

LocalSocket(sockType: Int)

Creates a AF_LOCAL/UNIX domain stream socket with given socket type

Public methods
open Unit
bind(bindpoint: LocalSocketAddress!)

Binds this socket to an endpoint name.

open Unit

Closes the socket.

open Unit

Connects this socket to an endpoint.

open Unit
connect(endpoint: LocalSocketAddress!, timeout: Int)

open Array<FileDescriptor!>!

Retrieves a set of file descriptors that a peer has sent through an ancillary message.

open FileDescriptor!

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

open InputStream!

Retrieves the input stream for this instance.

open LocalSocketAddress!

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

open OutputStream!

Retrieves the output stream for this instance.

open Credentials!

Retrieves the credentials of this socket's peer.

open Int

open LocalSocketAddress!

open Int

open Int

open Boolean

open Boolean

open Boolean

open Boolean

open Boolean

open Unit

Enqueues a set of file descriptors to send to the peer.

open Unit

open Unit

open Unit

open Unit

Shuts down the input side of the socket.

open Unit

Shuts down the output side of the socket.

open String

Returns a string representation of the object.

Constants

SOCKET_DGRAM

Added in API level 19
static val SOCKET_DGRAM: Int

Datagram socket type

Value: 1

SOCKET_SEQPACKET

Added in API level 19
static val SOCKET_SEQPACKET: Int

Sequential packet socket type

Value: 3

SOCKET_STREAM

Added in API level 19
static val SOCKET_STREAM: Int

Stream socket type

Value: 2

Public constructors

LocalSocket

Added in API level 1
LocalSocket()

Creates a AF_LOCAL/UNIX domain stream socket.

LocalSocket

Added in API level 19
LocalSocket(sockType: Int)

Creates a AF_LOCAL/UNIX domain stream socket with given socket type

Parameters
sockType Int: either SOCKET_DGRAM, SOCKET_STREAM or SOCKET_SEQPACKET

Public methods

bind

Added in API level 1
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

Added in API level 1
open fun close(): Unit

Closes the socket.

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

connect

Added in API level 1
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.

connect

Added in API level 1
open fun connect(
    endpoint: LocalSocketAddress!,
    timeout: Int
): Unit

getAncillaryFileDescriptors

Added in API level 1
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

Added in API level 1
open fun getFileDescriptor(): FileDescriptor!

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

Return
FileDescriptor! fd or null

getInputStream

Added in API level 1
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

Added in API level 1
open fun getLocalSocketAddress(): LocalSocketAddress!

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

Return
LocalSocketAddress! Local address or null if anonymous

getOutputStream

Added in API level 1
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

Added in API level 1
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

Added in API level 1
open fun getReceiveBufferSize(): Int

getRemoteSocketAddress

Added in API level 1
open fun getRemoteSocketAddress(): LocalSocketAddress!

getSendBufferSize

Added in API level 1
open fun getSendBufferSize(): Int

getSoTimeout

Added in API level 1
open fun getSoTimeout(): Int

isBound

Added in API level 1
open fun isBound(): Boolean

isClosed

Added in API level 1
open fun isClosed(): Boolean

isConnected

Added in API level 1
open fun isConnected(): Boolean

isInputShutdown

Added in API level 1
open fun isInputShutdown(): Boolean

isOutputShutdown

Added in API level 1
open fun isOutputShutdown(): Boolean

setFileDescriptorsForSend

Added in API level 1
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

Added in API level 1
open fun setReceiveBufferSize(size: Int): Unit

setSendBufferSize

Added in API level 1
open fun setSendBufferSize(n: Int): Unit

setSoTimeout

Added in API level 1
open fun setSoTimeout(n: Int): Unit

shutdownInput

Added in API level 1
open fun shutdownInput(): Unit

Shuts down the input side of the socket.

Exceptions
java.io.IOException

shutdownOutput

Added in API level 1
open fun shutdownOutput(): Unit

Shuts down the output side of the socket.

Exceptions
java.io.IOException

toString

Added in API level 1
open fun toString(): String

Returns a string representation of the object.

Return
String a string representation of the object.