Sam
02/01/2023, 5:29 PMPosixException.AddressAlreadyInUseException: EADDRINUSE (48): Address already in use
Does anyone know if there's a way of registering an uncaught exception handler to the Ktor server so I can handle this gracefully. (Or a proper fix would be welcome).
I've tried wrapping the whole thing in a coroutine scope launch block with a coroutine exception handler but that doesn't work.
embeddedServer(CIO, port = 8080) {
routing {
get("/") {
call.respondText("Hello, world!")
}
}
}.start(wait = true)
ephemient
02/01/2023, 6:26 PMport = 0
, it should automatically choose a free port. after it is started, you can find what port it ended up on through .resolvedConnectors()
Sam
02/01/2023, 6:57 PMephemient
02/01/2023, 7:04 PMtry
-catch
around .start()
not work? (I don't know if there's any iOS-specific oddities there)Sam
02/01/2023, 7:05 PMephemient
02/01/2023, 7:06 PMSO_REUSEADDR
socket option (see https://stackoverflow.com/a/2270357 for explanation) but it doesn't look like embeddedServer
has any way to customize how the server socket is bound 😞Sam
02/01/2023, 7:07 PMembeddedServer
behaviour at a lower level to access this api? From what I can see it only seems to be exposed to JVM? (If you don't know off the top of your head that's cool, just wondering)port=0
trick, thank you so much ❤️ )ephemient
02/01/2023, 7:26 PMembeddedServer
behavior, I don't think it's using anything internal… but it looks like a pain :(port=0
trick is a fairly common use of the socket API, it's not just a ktor thingSam
02/01/2023, 7:27 PMephemient
04/21/2023, 12:35 AMembeddedServer(CIO, port = 8080, configure = { reuseAddress = true }) {
Sam
04/24/2023, 5:04 PM