Stay organized with collections
Save and categorize content based on your preferences.
LocalServerSocket
open class LocalServerSocket : Closeable
Non-standard class for creating an inbound UNIX-domain socket in the Linux abstract namespace.
Summary
Public constructors |
Create a LocalServerSocket from a file descriptor that's already been created and bound.
|
Creates a new server socket listening at specified name.
|
Public methods |
open LocalSocket! |
Accepts a new connection to the socket.
|
open Unit |
Closes server socket.
|
open FileDescriptor! |
Returns file descriptor or null if not yet open/already closed
|
open LocalSocketAddress! |
Obtains the socket's local address
|
Public constructors
LocalServerSocket
LocalServerSocket(fd: FileDescriptor!)
Create a LocalServerSocket from a file descriptor that's already been created and bound. listen() will be called immediately on it. Used for cases where file descriptors are passed in via environment variables. The passed-in FileDescriptor is not managed by this class and must be closed by the caller. Calling #close() on a socket created by this method has no effect.
Exceptions |
java.io.IOException |
|
LocalServerSocket
LocalServerSocket(name: String!)
Creates a new server socket listening at specified name. On the Android platform, the name is created in the Linux abstract namespace (instead of on the filesystem).
Parameters |
name |
String!: address for socket |
Exceptions |
java.io.IOException |
|
Public methods
accept
open fun accept(): LocalSocket!
Accepts a new connection to the socket. Blocks until a new connection arrives.
Return |
LocalSocket! |
a socket representing the new connection. |
Exceptions |
java.io.IOException |
|
close
open fun close(): Unit
Closes server socket.
Exceptions |
java.lang.Exception |
if this resource cannot be closed |
java.io.IOException |
|
getFileDescriptor
open fun getFileDescriptor(): FileDescriptor!
Returns file descriptor or null if not yet open/already closed
getLocalSocketAddress
open fun getLocalSocketAddress(): LocalSocketAddress!
Obtains the socket's local address
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# LocalServerSocket\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nLocalServerSocket\n=================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/net/LocalServerSocket \"View this page in Java\") \n\n```\nopen class LocalServerSocket : Closeable\n```\n\n|---|------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.net.LocalServerSocket](#) |\n\nNon-standard class for creating an inbound UNIX-domain socket in the Linux abstract namespace.\n\nSummary\n-------\n\n| Public constructors ||\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [LocalServerSocket](#LocalServerSocket(java.io.FileDescriptor))`(`fd:` `[FileDescriptor](../../java/io/FileDescriptor.html#)!`)` Create a LocalServerSocket from a file descriptor that's already been created and bound. |\n| [LocalServerSocket](#LocalServerSocket(kotlin.String))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Creates a new server socket listening at specified name. |\n\n| Public methods ||\n|-----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|\n| open [LocalSocket](/reference/kotlin/android/net/LocalSocket)! | [accept](#accept())`()` Accepts a new connection to the socket. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [close](#close())`()` Closes server socket. |\n| open [FileDescriptor](../../java/io/FileDescriptor.html#)! | [getFileDescriptor](#getFileDescriptor())`()` Returns file descriptor or null if not yet open/already closed |\n| open [LocalSocketAddress](/reference/kotlin/android/net/LocalSocketAddress)! | [getLocalSocketAddress](#getLocalSocketAddress())`()` Obtains the socket's local address |\n\nPublic constructors\n-------------------\n\n### LocalServerSocket\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nLocalServerSocket(fd: FileDescriptor!)\n```\n\nCreate a LocalServerSocket from a file descriptor that's already been created and bound. listen() will be called immediately on it. Used for cases where file descriptors are passed in via environment variables. The passed-in FileDescriptor is not managed by this class and must be closed by the caller. Calling #close() on a socket created by this method has no effect.\n\n| Parameters ||\n|------|------------------------------------------------------------------------------|\n| `fd` | [FileDescriptor](../../java/io/FileDescriptor.html#)!: bound file descriptor |\n\n| Exceptions ||\n|-----------------------|---|\n| `java.io.IOException` | |\n\n### LocalServerSocket\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nLocalServerSocket(name: String!)\n```\n\nCreates a new server socket listening at specified name. On the Android platform, the name is created in the Linux abstract namespace (instead of on the filesystem).\n\n| Parameters ||\n|--------|-------------------------------------------------------------------------------------------------------|\n| `name` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: address for socket |\n\n| Exceptions ||\n|-----------------------|---|\n| `java.io.IOException` | |\n\nPublic methods\n--------------\n\n### accept\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun accept(): LocalSocket!\n```\n\nAccepts a new connection to the socket. Blocks until a new connection arrives.\n\n| Return ||\n|-----------------------------------------------------------|-------------------------------------------|\n| [LocalSocket](/reference/kotlin/android/net/LocalSocket)! | a socket representing the new connection. |\n\n| Exceptions ||\n|-----------------------|---|\n| `java.io.IOException` | |\n\n### close\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun close(): Unit\n```\n\nCloses server socket.\n\n| Exceptions ||\n|-----------------------|-----------------------------------|\n| `java.lang.Exception` | if this resource cannot be closed |\n| `java.io.IOException` | |\n\n### getFileDescriptor\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getFileDescriptor(): FileDescriptor!\n```\n\nReturns file descriptor or null if not yet open/already closed\n\n| Return ||\n|-------------------------------------------------------|------------|\n| [FileDescriptor](../../java/io/FileDescriptor.html#)! | fd or null |\n\n### getLocalSocketAddress\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getLocalSocketAddress(): LocalSocketAddress!\n```\n\nObtains the socket's local address\n\n| Return ||\n|-------------------------------------------------------------------------|---------------|\n| [LocalSocketAddress](/reference/kotlin/android/net/LocalSocketAddress)! | local address |"]]