# IpSecManager.UdpEncapsulationSocket

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

# UdpEncapsulationSocket

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/net/IpSecManager.UdpEncapsulationSocket "View this page in Java")  

```
class UdpEncapsulationSocket : AutoCloseable
```

|---|----------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                     ||
| ↳ | [android.net.IpSecManager.UdpEncapsulationSocket](https://developer.android.com/reference/kotlin/android/net/IpSecManager.UdpEncapsulationSocket#) |

This class provides access to a UDP encapsulation Socket.

`UdpEncapsulationSocket`wraps a system-provided datagram socket intended for IKEv2 signalling and UDP encapsulated IPsec traffic. Instances can be obtained by calling android.net.IpSecManager#openUdpEncapsulationSocket. The provided socket cannot be re-bound by the caller. The caller should not close the`FileDescriptor`returned by[getFileDescriptor](https://developer.android.com/reference/kotlin/android/net/IpSecManager.UdpEncapsulationSocket#getFileDescriptor()), but should use[close](https://developer.android.com/reference/kotlin/android/net/IpSecManager.UdpEncapsulationSocket#close())instead.

Allowing the user to close or unbind a UDP encapsulation socket could impact the traffic of the next user who binds to that port. To prevent this scenario, these sockets are held open by the system so that they may only be closed by calling[close](https://developer.android.com/reference/kotlin/android/net/IpSecManager.UdpEncapsulationSocket#close())or when the user process exits.

## Summary

|                                                                                                                                       Public methods                                                                                                                                        ||
|------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)                   | [close](https://developer.android.com/reference/kotlin/android/net/IpSecManager.UdpEncapsulationSocket#close())`()` Close this socket.                                                      |
| [FileDescriptor](https://developer.android.com/reference/kotlin/java/io/FileDescriptor.html#)! | [getFileDescriptor](https://developer.android.com/reference/kotlin/android/net/IpSecManager.UdpEncapsulationSocket#getFileDescriptor())`()` Get the encapsulation socket's file descriptor. |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                     | [getPort](https://developer.android.com/reference/kotlin/android/net/IpSecManager.UdpEncapsulationSocket#getPort())`()` Get the bound port of the wrapped socket.                           |
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)               | [toString](https://developer.android.com/reference/kotlin/android/net/IpSecManager.UdpEncapsulationSocket#toString())`()` <br />                                                            |

|                                                                                                                 Protected methods                                                                                                                  ||
|------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [finalize](https://developer.android.com/reference/kotlin/android/net/IpSecManager.UdpEncapsulationSocket#finalize())`()` Check that the socket was closed properly. |

## Public methods

### close

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

```
fun close(): Unit
```

Close this socket.

This closes the wrapped socket. Open encapsulation sockets count against a user's resource limits, and forgetting to close them eventually will result in[ResourceUnavailableException](https://developer.android.com/reference/kotlin/android/net/IpSecManager.ResourceUnavailableException)being thrown.

|                        Exceptions                        ||
|-----------------------|-----------------------------------|
| `java.lang.Exception` | if this resource cannot be closed |

### getFileDescriptor

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

```
fun getFileDescriptor(): FileDescriptor!
```

Get the encapsulation socket's file descriptor.  

### getPort

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

```
fun getPort(): Int
```

Get the bound port of the wrapped socket.  

### toString

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

```
fun toString(): String
```

|                                                          Return                                                          ||
|----------------------------------------------------------------------------------|----------------------------------------|
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | a string representation of the object. |

## Protected methods

### finalize

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

```
protected fun finalize(): Unit
```

Check that the socket was closed properly.

|                         Exceptions                         ||
|-----------------------|-------------------------------------|
| `java.lang.Throwable` | the`Exception`raised by this method |