Konstantin Zolotov
03/26/2023, 7:36 PMException in thread "main" java.net.BindException: Can't assign requested address
at java.base/sun.nio.ch.DatagramChannelImpl.send0(Native Method)
at java.base/sun.nio.ch.DatagramChannelImpl.sendFromNativeBuffer(DatagramChannelImpl.java:587)
at java.base/sun.nio.ch.DatagramChannelImpl.send(DatagramChannelImpl.java:549)
at java.base/sun.nio.ch.DatagramChannelImpl.send(DatagramChannelImpl.java:532)
at io.ktor.network.sockets.DatagramSendChannel$send$2$1.invokeSuspend(DatagramSendChannel.kt:80)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
This is my code:
fun main() {
runBlocking {
val selectorManager = SelectorManager(<http://Dispatchers.IO|Dispatchers.IO>)
val socket = aSocket(selectorManager)
.udp()
.bind(InetSocketAddress("127.0.0.1", 4756))
launch(<http://Dispatchers.IO|Dispatchers.IO>) {
for (datagram in socket.incoming) {
val bytes = datagram.packet.readBytes()
val decoded = decode(bytes)
<http://logger.info|logger.info>("Received: $decoded from ${datagram.address}")
}
}
val packet = BytePacketBuilder().apply { request }.build() // Here I create the packet to send, just raw bytes, nothing related to the problem
val message = Datagram(
packet = packet,
address = InetSocketAddress("<http://router.bittorrent.com|router.bittorrent.com>", 6881)
)
socket.send(message)
}
}
No idea why this is happening, can any one help me please?Aleksei Tirman [JB]
03/27/2023, 9:37 AM127.0.0.1
address in the .bind(InetSocketAddress("127.0.0.1", 4756))
to 0.0.0.0
?Konstantin Zolotov
03/27/2023, 10:01 AMAleksei Tirman [JB]
03/27/2023, 10:24 AM