public class

LocalSocket

extends Object
java.lang.Object
   ↳ android.net.LocalSocket

Class Overview

Creates a (non-server) socket in the UNIX-domain namespace. The interface here is not entirely unlike that of java.net.Socket

Summary

Public Constructors
LocalSocket()
Creates a AF_LOCAL/UNIX domain stream socket.
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()
synchronized boolean isBound()
boolean isClosed()
synchronized 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 containing a concise, human-readable description of this object.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public LocalSocket ()

Creates a AF_LOCAL/UNIX domain stream socket.

Public Methods

public 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 endpoint address
Throws
IOException

public void close ()

Closes the socket.

Throws
IOException

public void connect (LocalSocketAddress endpoint, int timeout)

Throws
IOException

public 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 endpoint address
Throws
IOException if socket is in invalid state or the address does not exist.

public 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
  • null or file descriptor array
Throws
IOException

public FileDescriptor getFileDescriptor ()

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

Returns
  • fd or null

public InputStream getInputStream ()

Retrieves the input stream for this instance.

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

public LocalSocketAddress getLocalSocketAddress ()

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

Returns
  • Local address or null if anonymous

public OutputStream getOutputStream ()

Retrieves the output stream for this instance.

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

public Credentials getPeerCredentials ()

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

Returns
  • non-null; peer credentials
Throws
IOException

public int getReceiveBufferSize ()

Throws
IOException

public LocalSocketAddress getRemoteSocketAddress ()

public int getSendBufferSize ()

Throws
IOException

public int getSoTimeout ()

Throws
IOException

public synchronized boolean isBound ()

public boolean isClosed ()

public synchronized boolean isConnected ()

public boolean isInputShutdown ()

public boolean isOutputShutdown ()

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

public void setReceiveBufferSize (int size)

Throws
IOException

public void setSendBufferSize (int n)

Throws
IOException

public void setSoTimeout (int n)

Throws
IOException

public void shutdownInput ()

Shuts down the input side of the socket.

Throws
IOException

public void shutdownOutput ()

Shuts down the output side of the socket.

Throws
IOException

public String toString ()

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation simply concatenates the class name, the '@' sign and a hexadecimal representation of the object's hashCode(), that is, it is equivalent to the following expression:

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

Returns
  • a printable representation of this object.