Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Options reference

socketOptions { } builds an immutable snapshot. Options are read when the client is created — mutating the builder afterwards changes nothing, and reconfiguring means building new options and reconnecting.

socketOptions {
    path = "/socket.io/"
    transports(Transports.POLLING, Transports.WEBSOCKET)
    upgrade = true

    auth { put("token", jwt) }
    extraHeaders { put("Authorization", listOf("Bearer $jwt")) }

    timeoutMs = 20_000
    ackTimeoutMs = 0

    reconnection = true
    reconnectionAttempts = Int.MAX_VALUE
    reconnectionDelayMs = 1_000
    reconnectionDelayMaxMs = 5_000
    randomizationFactor = 0.5

    multiplex = true
    forceNew = false

    trustAllCerts = false
    httpClient = null
    logger = Logger.NoOp
}

Connection

OptionDefault
path/socket.io/Server’s Engine.IO endpoint. Change only if the server did
transports(…)polling, websocketAllowed transports, in preference order
upgradetrueUpgrade polling → websocket when the server offers it
timeoutMs20_000Budget for the initial connection

Transports accept library constants or plain strings — "websocket" works as well as Transports.WEBSOCKET. Unrecognised names are dropped at build(), matching the JavaScript client. An empty list fails fast with IllegalArgumentException.

transports(Transports.WEBSOCKET) alone skips polling entirely: one fewer round trip, at the cost of failing outright on networks where only long-polling survives.

Acknowledgements

OptionDefault
ackTimeoutMs0 — disabledHow long emitWithAck waits before failing

Zero means wait forever. Set it to something finite unless you are certain the server always replies. See Acknowledgements.

Reconnection

Covered in Reconnection.

Event buffering

eventBuffer {
    capacity = 64
    overflow = EventBufferOverflow.DROP_OLDEST
}

See Receiving events.

Multiplexing

OptionDefault
multiplextrueShare one engine per scheme://host:port
forceNewfalseOwn engine, not registered

See Namespaces.

Transport and TLS

OptionDefault
httpClientnullReuse your own Ktor client — see Sharing an HttpClient
trustAllCertsfalseDevelopment only — see TLS

Logging

logger defaults to Logger.NoOp. See Logging.