diff --git a/ktor-network/api/ktor-network.api b/ktor-network/api/ktor-network.api index 13d0d4eb9fd..7fb6a096f8a 100644 --- a/ktor-network/api/ktor-network.api +++ b/ktor-network/api/ktor-network.api @@ -341,7 +341,9 @@ public final class io/ktor/network/sockets/TypeOfService$Companion { public final class io/ktor/network/sockets/UDPSocketBuilder : io/ktor/network/sockets/Configurable { public final fun bind (Lio/ktor/network/sockets/SocketAddress;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun bind (Ljava/lang/String;ILkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun bind$default (Lio/ktor/network/sockets/UDPSocketBuilder;Lio/ktor/network/sockets/SocketAddress;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun bind$default (Lio/ktor/network/sockets/UDPSocketBuilder;Ljava/lang/String;ILkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public synthetic fun configure (Lkotlin/jvm/functions/Function1;)Lio/ktor/network/sockets/Configurable; public fun configure (Lkotlin/jvm/functions/Function1;)Lio/ktor/network/sockets/UDPSocketBuilder; public final fun connect (Lio/ktor/network/sockets/SocketAddress;Lio/ktor/network/sockets/SocketAddress;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; diff --git a/ktor-network/api/ktor-network.klib.api b/ktor-network/api/ktor-network.klib.api index c3700e181ed..3af84ac69cc 100644 --- a/ktor-network/api/ktor-network.klib.api +++ b/ktor-network/api/ktor-network.klib.api @@ -166,6 +166,7 @@ final class io.ktor.network.sockets/UDPSocketBuilder : io.ktor.network.sockets/C final fun (io.ktor.network.sockets/SocketOptions.UDPSocketOptions) // io.ktor.network.sockets/UDPSocketBuilder.options.|(io.ktor.network.sockets.SocketOptions.UDPSocketOptions){}[0] final suspend fun bind(io.ktor.network.sockets/SocketAddress? = ..., kotlin/Function1 = ...): io.ktor.network.sockets/BoundDatagramSocket // io.ktor.network.sockets/UDPSocketBuilder.bind|bind(io.ktor.network.sockets.SocketAddress?;kotlin.Function1){}[0] + final suspend fun bind(kotlin/String = ..., kotlin/Int = ..., kotlin/Function1 = ...): io.ktor.network.sockets/BoundDatagramSocket // io.ktor.network.sockets/UDPSocketBuilder.bind|bind(kotlin.String;kotlin.Int;kotlin.Function1){}[0] final suspend fun connect(io.ktor.network.sockets/SocketAddress, io.ktor.network.sockets/SocketAddress? = ..., kotlin/Function1 = ...): io.ktor.network.sockets/ConnectedDatagramSocket // io.ktor.network.sockets/UDPSocketBuilder.connect|connect(io.ktor.network.sockets.SocketAddress;io.ktor.network.sockets.SocketAddress?;kotlin.Function1){}[0] } diff --git a/ktor-network/common/src/io/ktor/network/sockets/UDPSocketBuilder.kt b/ktor-network/common/src/io/ktor/network/sockets/UDPSocketBuilder.kt index eb8402565e6..7b680260c45 100644 --- a/ktor-network/common/src/io/ktor/network/sockets/UDPSocketBuilder.kt +++ b/ktor-network/common/src/io/ktor/network/sockets/UDPSocketBuilder.kt @@ -21,6 +21,15 @@ public class UDPSocketBuilder internal constructor( configure: SocketOptions.UDPSocketOptions.() -> Unit = {} ): BoundDatagramSocket = udpBind(selector, localAddress, options.udp().apply(configure)) + /** + * Bind server socket at [port] to listen to [hostname]. + */ + public suspend fun bind( + hostname: String = "0.0.0.0", + port: Int = 0, + configure: SocketOptions.UDPSocketOptions.() -> Unit = {} + ): BoundDatagramSocket = bind(InetSocketAddress(hostname, port), configure) + /** * Create a datagram socket to listen datagrams at [localAddress] and set to [remoteAddress]. */ diff --git a/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/UDPSocketTest.kt b/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/UDPSocketTest.kt index 7c5b9f49893..9ed72e30ba6 100644 --- a/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/UDPSocketTest.kt +++ b/ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/UDPSocketTest.kt @@ -197,7 +197,7 @@ class UDPSocketTest { fun testSendReceive() = testSockets { selector -> aSocket(selector) .udp() - .bind(InetSocketAddress("127.0.0.1", 8000)) { + .bind("127.0.0.1", 8000) { reuseAddress = true } .use { socket ->