CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-ktor--ktor-server-netty-jvm

Netty-based HTTP server engine for Ktor framework providing high-performance asynchronous server capabilities

Pending
Overview
Eval results
Files

standalone-server.mddocs/

Standalone Server Execution

Main entry point for running standalone Ktor Netty servers from command line or application main functions.

Capabilities

EngineMain Object

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)
}

Command Line Arguments

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 directly

Example 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.samples

Configuration File Support

EngineMain 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 ]
    }
}

Application Module Loading

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")
        }
    }
}

Environment Variables

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}
    }
}

Development vs Production

EngineMain automatically detects development mode and adjusts behavior:

Development Mode Features:

  • Auto-reload on code changes (when watch paths are configured)
  • Detailed error pages
  • Additional logging

Production Mode Features:

  • Optimized performance settings
  • Minimal error information exposure
  • Production-ready defaults
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

docs

coroutine-integration.md

engine-implementation.md

index.md

platform-optimization.md

request-response.md

server-configuration.md

standalone-server.md

tile.json