Netty-based HTTP server engine for Ktor framework providing high-performance asynchronous server capabilities
—
Main entry point for running standalone Ktor Netty servers from command line or application main functions.
Main object for running standalone Netty servers with command-line argument support and configuration loading.
/**
* Netty engine main entry point for standalone applications
*/
object EngineMain {
/**
* Main function for starting EngineMain with Netty
* Creates an embedded Netty application with an environment built from command line arguments
* @param args Command line arguments for server configuration
*/
@JvmStatic
fun main(args: Array<String>)
/**
* Creates an instance of the embedded Netty server without starting it
* @param args Command line arguments for configuring the server
* @return An instance of EmbeddedServer with the specified configuration
*/
fun createServer(
args: Array<String>
): EmbeddedServer<NettyApplicationEngine, NettyApplicationEngine.Configuration>
}Usage Examples:
import io.ktor.server.netty.*
// Basic standalone server
fun main(args: Array<String>) {
EngineMain.main(args)
}
// Create server without starting (for testing or custom startup logic)
fun main(args: Array<String>) {
val server = EngineMain.createServer(args)
// Perform additional setup
// ...
// Start when ready
server.start(wait = true)
}The EngineMain accepts standard command line arguments for server configuration:
Common Arguments:
-port=8080 - Server port-host=0.0.0.0 - Bind address-config=application.conf - Configuration file path-P:ktor.deployment.port=8080 - Set configuration property directlyExample Usage:
# Run with specific port
java -jar myapp.jar -port=8080
# Run with custom configuration
java -jar myapp.jar -config=production.conf
# Run with multiple properties
java -jar myapp.jar -port=8080 -P:ktor.deployment.watch=io.ktor.samplesEngineMain supports loading configuration from HOCON files (application.conf):
ktor {
deployment {
port = 8080
host = "0.0.0.0"
# Netty-specific configuration
runningLimit = 64
shareWorkGroup = true
responseWriteTimeoutSeconds = 30
requestReadTimeoutSeconds = 0
tcpKeepAlive = true
maxInitialLineLength = 4096
maxHeaderSize = 8192
maxChunkSize = 8192
}
application {
modules = [ com.example.ApplicationKt.main ]
}
}EngineMain automatically loads and initializes application modules specified in configuration:
// Application.kt
package com.example
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
fun Application.main() {
routing {
get("/") {
call.respondText("Hello from standalone Ktor Netty server!")
}
get("/health") {
call.respondText("OK")
}
}
}EngineMain supports environment variable substitution in configuration files:
ktor {
deployment {
port = ${?PORT} # Uses PORT env var if available
host = ${?HOST} # Uses HOST env var if available
# Netty configuration from environment
runningLimit = ${?KTOR_RUNNING_LIMIT}
tcpKeepAlive = ${?KTOR_TCP_KEEP_ALIVE}
}
}EngineMain automatically detects development mode and adjusts behavior:
Development Mode Features:
Production Mode Features:
ktor {
development = true # Enable development mode
deployment {
watch = [ "classes", "resources" ] # Auto-reload paths
}
}Install with Tessl CLI
npx tessl i tessl/maven-io-ktor--ktor-server-netty-jvm