Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public class

LocalSocket

extends Object
implements Closeable
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

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 ()
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
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Constants

public static final int SOCKET_DGRAM

Datagram socket type

Constant Value: 1 (0x00000001)

public static final int SOCKET_SEQPACKET

Sequential packet socket type

Constant Value: 3 (0x00000003)

public static final int SOCKET_STREAM

Stream socket type

Constant Value: 2 (0x00000002)

Public Constructors

public LocalSocket ()

Added in API level 1

Creates a AF_LOCAL/UNIX domain stream socket.

public LocalSocket (int sockType)

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

Public Methods

public void bind ( LocalSocketAddress bindpoint)

Added in 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

public void close ()

Added in API level 1

Closes the socket.

public void connect ( LocalSocketAddress endpoint, int timeout)

Added in API level 1

public void connect ( LocalSocketAddress endpoint)

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

Added in 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

public FileDescriptor getFileDescriptor ()

Added in API level 1

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

Returns
  • fd or null

public InputStream getInputStream ()

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

Added in API level 1

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

Returns
  • Local address or null if anonymous

public OutputStream getOutputStream ()

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

Added in API level 1

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

Returns
  • non-null; peer credentials

public int getReceiveBufferSize ()

Added in API level 1

public LocalSocketAddress getRemoteSocketAddress ()

Added in API level 1

public int getSendBufferSize ()

Added in API level 1

public int getSoTimeout ()

Added in API level 1

public synchronized boolean isBound ()

Added in API level 1

public boolean isClosed ()

Added in API level 1

public synchronized boolean isConnected ()

Added in API level 1

public boolean isInputShutdown ()

Added in API level 1

public boolean isOutputShutdown ()

Added in API level 1

public void setFileDescriptorsForSend ( FileDescriptor[] fds)

Added in 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)

Added in API level 1

public void setSendBufferSize (int n)

Added in API level 1

public void setSoTimeout (int n)

Added in API level 1

public void shutdownInput ()

Added in API level 1

Shuts down the input side of the socket.

public void shutdownOutput ()

Added in API level 1

Shuts down the output side of the socket.

public String toString ()

Added in 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.