Cristian Rosa
09/19/2021, 12:34 PM@Composable
fun MainScreen() {
val ktorServer = embeddedServer(Jetty, port = 8080,) {
...module declaration....
}
Column(Modifier.fillMaxSize(), Arrangement.spacedBy(5.dp)) {
Button(modifier = Modifier.align(Alignment.CenterHorizontally),
onClick = {
ktorServer.start(wait = false)
}
) {
Text("START")
}
Button(modifier = Modifier.align(Alignment.CenterHorizontally),
onClick = {
ktorServer.stop(5000, 6000, TimeUnit.MILLISECONDS)
}
) {
Text("STOP")
}
}
}
At the moment
• “start” button click works as expected and the server run properly
• “stop” doesn’t take any action at all!!!!
The only way, I figure out to stop the server is by shutdown-url, but in this way the all app is closed
(I would like to keep the compose windows open with the change of re-start server again)
Using EngineMain like this:
scope.launch(Dispatchers.Default) {
val args = arrayOf<String>()
EngineMain.main(args)
}
Again I can run the server but don’t know how to stop it.Aleksei Tirman [JB]
09/20/2021, 10:18 AMstop
on the server instance and then creating a new instance by calling embeddedServer
to replace the reference for your ktorServer
property. Unfortunately, there is no way to restart a server (KTOR-2762) because stop is actually means destroy.Cristian Rosa
09/20/2021, 7:47 PMwhat do you mean “calling stop on server instance” 🤔because at the moment if i run
ktorServer.stop(x,y,Timeunit.MILLISECONDS)
nothing happen!Aleksei Tirman [JB]
09/21/2021, 7:11 AMstop
?Cristian Rosa
09/21/2021, 8:59 AMWhat engine do you use?Engine of embeddedServer is set to Jetty
What do you expect to happen when you call stop ?I would like server get stopped (or killed due of that you said above) The strange behavior I can’t understand is: after declare a var like
ktorServer = embeddedServer(Jetty, port = 8080) {
authentication()
logging()
routing()
security()
serialization()
webSocket()
}
with ktorServer.start(false)
server started properly
with ktorServer.stop(1000, 2000, Timeunit.MILLISECONS)
server doesn’t stopAleksei Tirman [JB]
09/21/2021, 9:19 AMsuspend fun main(args: Array<String>): Unit = coroutineScope {
launch {
val server = embeddedServer(Jetty, port = 7070) {
routing {
get("/") {
call.respondText { "Hello" }
}
}
}
server.start(false)
delay(2000)
server.stop(1000, 2000, TimeUnit.MILLISECONDS)
println("stopped")
}
launch {
while (true) {}
}
}
Please file an issue and attach a code snippet there to reproduce your problem.Cristian Rosa
09/21/2021, 7:04 PM