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 ()

Since: API Level 1

Creates a AF_LOCAL/UNIX domain stream socket.

Public Methods

public void bind (LocalSocketAddress bindpoint)

Since: API Level 1

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 ()

Since: API Level 1

Closes the socket.

Throws
IOException

public void connect (LocalSocketAddress endpoint, int timeout)

Since: API Level 1

Throws
IOException

public void connect (LocalSocketAddress endpoint)

Since: API Level 1

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 ()

Since: API Level 1

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 ()

Since: API Level 1

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

Returns
  • fd or null

public InputStream getInputStream ()

Since: API Level 1

Retrieves the input stream for this instance.

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

public LocalSocketAddress getLocalSocketAddress ()

Since: API Level 1

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

Returns
  • Local address or null if anonymous

public OutputStream getOutputStream ()

Since: API Level 1

Retrieves the output stream for this instance.

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

public Credentials getPeerCredentials ()

Since: API Level 1

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

Returns
  • non-null; peer credentials
Throws
IOException

public int getReceiveBufferSize ()

Since: API Level 1

Throws
IOException

public LocalSocketAddress getRemoteSocketAddress ()

Since: API Level 1

public int getSendBufferSize ()

Since: API Level 1

Throws
IOException

public int getSoTimeout ()

Since: API Level 1

Throws
IOException

public synchronized boolean isBound ()

Since: API Level 1

public boolean isClosed ()

Since: API Level 1

public synchronized boolean isConnected ()

Since: API Level 1

public boolean isInputShutdown ()

Since: API Level 1

public boolean isOutputShutdown ()

Since: API Level 1

public void setFileDescriptorsForSend (FileDescriptor[] fds)

Since: API Level 1

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)

Since: API Level 1

Throws
IOException

public void setSendBufferSize (int n)

Since: API Level 1

Throws
IOException

public void setSoTimeout (int n)

Since: API Level 1

Throws
IOException

public void shutdownInput ()

Since: API Level 1

Shuts down the input side of the socket.

Throws
IOException

public void shutdownOutput ()

Since: API Level 1

Shuts down the output side of the socket.

Throws
IOException

public String toString ()

Since: API Level 1

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 is equivalent to the following expression:

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

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.