Most visited

Recently visited

Added in API level 1

LocalSocket

public class LocalSocket
extends Object implements Closeable

java.lang.Object
   ↳ 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

int SOCKET_DGRAM

Datagram socket type

int SOCKET_SEQPACKET

Sequential packet socket type

int SOCKET_STREAM

Stream socket type

Public constructors

LocalSocket()

Creates a AF_LOCAL/UNIX domain stream socket.

LocalSocket(int sockType)

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

Public methods

void bind(LocalSocketAddress bindpoint)

Binds this socket to an endpoint name.

void close()

Closes the socket.

void connect(LocalSocketAddress endpoint, int timeout)
void connect(LocalSocketAddress endpoint)

Connects this socket to an endpoint.

FileDescriptor[] getAncillaryFileDescriptors()

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

FileDescriptor getFileDescriptor()

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

InputStream getInputStream()

Retrieves the input stream for this instance.

LocalSocketAddress getLocalSocketAddress()

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

OutputStream getOutputStream()

Retrieves the output stream for this instance.

Credentials getPeerCredentials()

Retrieves the credentials of this socket's peer.

int getReceiveBufferSize()
LocalSocketAddress getRemoteSocketAddress()
int getSendBufferSize()
int getSoTimeout()
boolean isBound()
boolean isClosed()
boolean isConnected()
boolean isInputShutdown()
boolean isOutputShutdown()
void setFileDescriptorsForSend(FileDescriptor[] fds)

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

void setReceiveBufferSize(int size)
void setSendBufferSize(int n)
void setSoTimeout(int n)
void shutdownInput()

Shuts down the input side of the socket.

void shutdownOutput()

Shuts down the output side of the socket.

String toString()

Returns a string representation of the object.

Inherited methods

From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Constants

SOCKET_DGRAM

Added in API level 19
int SOCKET_DGRAM

Datagram socket type

Constant Value: 1 (0x00000001)

SOCKET_SEQPACKET

Added in API level 19
int SOCKET_SEQPACKET

Sequential packet socket type

Constant Value: 3 (0x00000003)

SOCKET_STREAM

Added in API level 19
int SOCKET_STREAM

Stream socket type

Constant Value: 2 (0x00000002)

Public constructors

LocalSocket

Added in API level 1
LocalSocket ()

Creates a AF_LOCAL/UNIX domain stream socket.

LocalSocket

Added in API level 19
LocalSocket (int sockType)

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
void bind (LocalSocketAddress bindpoint)

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
Throws
IOException

close

Added in API level 1
void close ()

Closes the socket.

Throws
IOException

connect

Added in API level 1
void connect (LocalSocketAddress endpoint, 
                int timeout)

Parameters
endpoint LocalSocketAddress
timeout int
Throws
IOException

connect

Added in API level 1
void connect (LocalSocketAddress endpoint)

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

Parameters
endpoint LocalSocketAddress: endpoint address
Throws
IOException if socket is in invalid state or the address does not exist.

getAncillaryFileDescriptors

Added in API level 1
FileDescriptor[] getAncillaryFileDescriptors ()

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.

Returns
FileDescriptor[] null or file descriptor array
Throws
IOException

getFileDescriptor

Added in API level 1
FileDescriptor getFileDescriptor ()

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

Returns
FileDescriptor fd or null

getInputStream

Added in API level 1
InputStream getInputStream ()

Retrieves the input stream for this instance.

Returns
InputStream input stream
Throws
IOException if socket has been closed or cannot be created.

getLocalSocketAddress

Added in API level 1
LocalSocketAddress getLocalSocketAddress ()

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

Returns
LocalSocketAddress Local address or null if anonymous

getOutputStream

Added in API level 1
OutputStream getOutputStream ()

Retrieves the output stream for this instance.

Returns
OutputStream output stream
Throws
IOException if socket has been closed or cannot be created.

getPeerCredentials

Added in API level 1
Credentials getPeerCredentials ()

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

Returns
Credentials non-null; peer credentials
Throws
IOException

getReceiveBufferSize

Added in API level 1
int getReceiveBufferSize ()

Returns
int
Throws
IOException

getRemoteSocketAddress

Added in API level 1
LocalSocketAddress getRemoteSocketAddress ()

Returns
LocalSocketAddress

getSendBufferSize

Added in API level 1
int getSendBufferSize ()

Returns
int
Throws
IOException

getSoTimeout

Added in API level 1
int getSoTimeout ()

Returns
int
Throws
IOException

isBound

Added in API level 1
boolean isBound ()

Returns
boolean

isClosed

Added in API level 1
boolean isClosed ()

Returns
boolean

isConnected

Added in API level 1
boolean isConnected ()

Returns
boolean

isInputShutdown

Added in API level 1
boolean isInputShutdown ()

Returns
boolean

isOutputShutdown

Added in API level 1
boolean isOutputShutdown ()

Returns
boolean

setFileDescriptorsForSend

Added in API level 1
void setFileDescriptorsForSend (FileDescriptor[] fds)

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 FileDescriptor: non-null; file descriptors to send.

setReceiveBufferSize

Added in API level 1
void setReceiveBufferSize (int size)

Parameters
size int
Throws
IOException

setSendBufferSize

Added in API level 1
void setSendBufferSize (int n)

Parameters
n int
Throws
IOException

setSoTimeout

Added in API level 1
void setSoTimeout (int n)

Parameters
n int
Throws
IOException

shutdownInput

Added in API level 1
void shutdownInput ()

Shuts down the input side of the socket.

Throws
IOException

shutdownOutput

Added in API level 1
void shutdownOutput ()

Shuts down the output side of the socket.

Throws
IOException

toString

Added in API level 1
String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
String a string representation of the object.

Hooray!