Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/net/LocalSocket#constants) \| [Ctors](https://developer.android.com/reference/android/net/LocalSocket#pubctors) \| [Methods](https://developer.android.com/reference/android/net/LocalSocket#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/net/LocalSocket#inhmethods)

# LocalSocket

*** ** * ** ***

` public class LocalSocket `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/java/io/Closeable `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.net.LocalSocket |

<br />

*** ** * ** ***

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` | `https://developer.android.com/reference/android/net/LocalSocket#SOCKET_DGRAM` Datagram socket type |
| `int` | `https://developer.android.com/reference/android/net/LocalSocket#SOCKET_SEQPACKET` Sequential packet socket type |
| `int` | `https://developer.android.com/reference/android/net/LocalSocket#SOCKET_STREAM` Stream socket type |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/net/LocalSocket#LocalSocket()() ` Creates a AF_LOCAL/UNIX domain stream socket. |
| ` https://developer.android.com/reference/android/net/LocalSocket#LocalSocket(int)(int sockType) ` Creates a AF_LOCAL/UNIX domain socket with the given socket type. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/net/LocalSocket#bind(android.net.LocalSocketAddress)(https://developer.android.com/reference/android/net/LocalSocketAddress bindpoint) ` Binds this socket to an endpoint name. |
| ` void` | ` https://developer.android.com/reference/android/net/LocalSocket#close()() ` Closes the socket. |
| ` void` | ` https://developer.android.com/reference/android/net/LocalSocket#connect(android.net.LocalSocketAddress,%20int)(https://developer.android.com/reference/android/net/LocalSocketAddress endpoint, int timeout) ` |
| ` void` | ` https://developer.android.com/reference/android/net/LocalSocket#connect(android.net.LocalSocketAddress)(https://developer.android.com/reference/android/net/LocalSocketAddress endpoint) ` Connects this socket to an endpoint. |
| ` https://developer.android.com/reference/java/io/FileDescriptor` | ` https://developer.android.com/reference/android/net/LocalSocket#getAncillaryFileDescriptors()() ` Retrieves a set of file descriptors that a peer has sent through an ancillary message. |
| ` https://developer.android.com/reference/java/io/FileDescriptor` | ` https://developer.android.com/reference/android/net/LocalSocket#getFileDescriptor()() ` Returns file descriptor or null if not yet open/already closed |
| ` https://developer.android.com/reference/java/io/InputStream` | ` https://developer.android.com/reference/android/net/LocalSocket#getInputStream()() ` Retrieves the input stream for this instance. |
| ` https://developer.android.com/reference/android/net/LocalSocketAddress` | ` https://developer.android.com/reference/android/net/LocalSocket#getLocalSocketAddress()() ` Retrieves the name that this socket is bound to, if any. |
| ` https://developer.android.com/reference/java/io/OutputStream` | ` https://developer.android.com/reference/android/net/LocalSocket#getOutputStream()() ` Retrieves the output stream for this instance. |
| ` https://developer.android.com/reference/android/net/Credentials` | ` https://developer.android.com/reference/android/net/LocalSocket#getPeerCredentials()() ` Retrieves the credentials of this socket's peer. |
| ` int` | ` https://developer.android.com/reference/android/net/LocalSocket#getReceiveBufferSize()() ` |
| ` https://developer.android.com/reference/android/net/LocalSocketAddress` | ` https://developer.android.com/reference/android/net/LocalSocket#getRemoteSocketAddress()() ` |
| ` int` | ` https://developer.android.com/reference/android/net/LocalSocket#getSendBufferSize()() ` |
| ` int` | ` https://developer.android.com/reference/android/net/LocalSocket#getSoTimeout()() ` |
| ` boolean` | ` https://developer.android.com/reference/android/net/LocalSocket#isBound()() ` |
| ` boolean` | ` https://developer.android.com/reference/android/net/LocalSocket#isClosed()() ` |
| ` boolean` | ` https://developer.android.com/reference/android/net/LocalSocket#isConnected()() ` |
| ` boolean` | ` https://developer.android.com/reference/android/net/LocalSocket#isInputShutdown()() ` |
| ` boolean` | ` https://developer.android.com/reference/android/net/LocalSocket#isOutputShutdown()() ` |
| ` void` | ` https://developer.android.com/reference/android/net/LocalSocket#setFileDescriptorsForSend(java.io.FileDescriptor[])(https://developer.android.com/reference/java/io/FileDescriptor fds) ` Enqueues a set of file descriptors to send to the peer. |
| ` void` | ` https://developer.android.com/reference/android/net/LocalSocket#setReceiveBufferSize(int)(int size) ` |
| ` void` | ` https://developer.android.com/reference/android/net/LocalSocket#setSendBufferSize(int)(int n) ` |
| ` void` | ` https://developer.android.com/reference/android/net/LocalSocket#setSoTimeout(int)(int n) ` |
| ` void` | ` https://developer.android.com/reference/android/net/LocalSocket#shutdownInput()() ` Shuts down the input side of the socket. |
| ` void` | ` https://developer.android.com/reference/android/net/LocalSocket#shutdownOutput()() ` Shuts down the output side of the socket. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/net/LocalSocket#toString()() ` Returns a string representation of the object. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/java/io/Closeable ` ` abstract void` ` https://developer.android.com/reference/java/io/Closeable#close()() `

Closes this stream and releases any system resources associated with it.
From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` ` abstract void` ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() `

Closes this resource, relinquishing any underlying resources.

## Constants

### SOCKET_DGRAM

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SOCKET_DGRAM
```

Datagram socket type

<br />

Constant Value: 1 (0x00000001)

### SOCKET_SEQPACKET

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SOCKET_SEQPACKET
```

Sequential packet socket type

<br />

Constant Value: 3 (0x00000003)

### SOCKET_STREAM

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SOCKET_STREAM
```

Stream socket type

<br />

Constant Value: 2 (0x00000002)

## Public constructors

### LocalSocket

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public LocalSocket ()
```

Creates a AF_LOCAL/UNIX domain stream socket.

<br />

### LocalSocket

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public LocalSocket (int sockType)
```

Creates a AF_LOCAL/UNIX domain socket with the given socket type.

<br />

| Parameters ||
|---|---|
| `sockType` | `int`: either `https://developer.android.com/reference/android/net/LocalSocket#SOCKET_DGRAM`, `https://developer.android.com/reference/android/net/LocalSocket#SOCKET_STREAM` or `https://developer.android.com/reference/android/net/LocalSocket#SOCKET_SEQPACKET` <br /> |

## Public methods

### bind

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Parameters ||
|---|---|
| `bindpoint` | `LocalSocketAddress`: endpoint address <br /> |

| Throws ||
|---|---|
|   | java.io.IOException |
| `https://developer.android.com/reference/java/io/IOException` |   |

### close

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void close ()
```

Closes the socket.

<br />

| Throws ||
|---|---|
|   | java.io.IOException |
| `https://developer.android.com/reference/java/io/IOException` |   |

### connect

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

<br />

<br />

| Parameters ||
|---|---|
| `endpoint` | `LocalSocketAddress` <br /> |
| `timeout` | `int` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### connect

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void connect (LocalSocketAddress endpoint)
```

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

<br />

| Parameters ||
|---|---|
| `endpoint` | `LocalSocketAddress`: endpoint address <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if socket is in invalid state or the address does not exist. |

### getAncillaryFileDescriptors

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/io/FileDescriptor` | null or file descriptor array <br /> |

| Throws ||
|---|---|
|   | java.io.IOException |
| `https://developer.android.com/reference/java/io/IOException` |   |

### getFileDescriptor

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public FileDescriptor getFileDescriptor ()
```

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/io/FileDescriptor` | fd or null <br /> |

### getInputStream

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public InputStream getInputStream ()
```

Retrieves the input stream for this instance. Closing this stream is equivalent to closing the entire socket and its associated streams using `https://developer.android.com/reference/android/net/LocalSocket#close()`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/io/InputStream` | input stream <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if socket has been closed or cannot be created. |

### getLocalSocketAddress

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public LocalSocketAddress getLocalSocketAddress ()
```

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/LocalSocketAddress` | Local address or null if anonymous <br /> |

### getOutputStream

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public OutputStream getOutputStream ()
```

Retrieves the output stream for this instance. Closing this stream is equivalent to closing the entire socket and its associated streams using `https://developer.android.com/reference/android/net/LocalSocket#close()`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/io/OutputStream` | output stream <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if socket has been closed or cannot be created. |

### getPeerCredentials

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Credentials getPeerCredentials ()
```

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/Credentials` | non-null; peer credentials <br /> |

| Throws ||
|---|---|
|   | java.io.IOException |
| `https://developer.android.com/reference/java/io/IOException` |   |

### getReceiveBufferSize

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getReceiveBufferSize ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### getRemoteSocketAddress

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public LocalSocketAddress getRemoteSocketAddress ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/LocalSocketAddress` | <br /> |

### getSendBufferSize

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getSendBufferSize ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### getSoTimeout

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getSoTimeout ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### isBound

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isBound ()
```

<br />

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isClosed

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isClosed ()
```

<br />

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isConnected

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isConnected ()
```

<br />

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isInputShutdown

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isInputShutdown ()
```

<br />

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isOutputShutdown

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isOutputShutdown ()
```

<br />

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### setFileDescriptorsForSend

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Parameters ||
|---|---|
| `fds` | `FileDescriptor`: non-null; file descriptors to send. <br /> |

### setReceiveBufferSize

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setReceiveBufferSize (int size)
```

<br />

<br />

| Parameters ||
|---|---|
| `size` | `int` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### setSendBufferSize

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setSendBufferSize (int n)
```

<br />

<br />

| Parameters ||
|---|---|
| `n` | `int` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### setSoTimeout

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setSoTimeout (int n)
```

<br />

<br />

| Parameters ||
|---|---|
| `n` | `int` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### shutdownInput

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void shutdownInput ()
```

Shuts down the input side of the socket.

<br />

| Throws ||
|---|---|
|   | java.io.IOException |
| `https://developer.android.com/reference/java/io/IOException` |   |

### shutdownOutput

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void shutdownOutput ()
```

Shuts down the output side of the socket.

<br />

| Throws ||
|---|---|
|   | java.io.IOException |
| `https://developer.android.com/reference/java/io/IOException` |   |

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns a string representation of the object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |