https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
ktor
  • s

    Sam

    10/07/2018, 9:52 PM
    When making an api call with ktor-client an error while deserializing a response under iOS. The same code works fine in a jvm test. I'm modeling the app after the conference app and can't see any differences in how it's doing things versus what I'm trying.
    kotlin.IllegalArgumentException: Charset ISO_8859_1 is not supported
    e
    • 2
    • 2
  • o

    otakusenpai

    10/08/2018, 2:38 PM
    can anyone give me an example of the SSL connection in raw sockets?
    • 1
    • 2
  • d

    Dias

    10/08/2018, 3:28 PM
    Hi, I am not sure how to use webjars feature. I installed it, and was trying to call localhost:8080/webjars path, but it doesn't work and I don't see that it's registering any routing. How is it supposed to work? Do I have to register dummy root routing?
    e
    c
    • 3
    • 3
  • o

    otakusenpai

    10/08/2018, 4:10 PM
    can anyone pls just tell me what dependencies I should have for this line:
    socket = aSocket(ActorSelectorManager(ioCoroutineDispatcher)).tcp().connect(InetSocketAddress(address,port)).tls()
    d
    • 2
    • 56
  • s

    samir

    10/08/2018, 8:18 PM
    Hey guys, I am trying to figure out how can I make my ktor app free all used resources on shutdown. I am using the event
    ApplicationStopping
    , it works well with the tests but when I run the app locally with Intellij or by using
    ./gradlew run
    the handler never gets called when I stop the app and I don’t see the logs
    Application stopping
    &
    Application stopped
    . Is there any way to make sure the handler always gets called even when stopping the app from intellij or with ./gradlew ?
    d
    • 2
    • 1
  • d

    Dias

    10/08/2018, 11:07 PM
    https://kotlinlang.slack.com/archives/C0A974TJ9/p1539012504000100 Anyone can answer this please?
    d
    • 2
    • 8
  • o

    otakusenpai

    10/09/2018, 4:55 AM
    @Deactivated User hey sorry to ping you directly I was running the TestBot with updated codebase and am having trouble trying to send a String through ByteWriteChannel
    output.writeByte(data.toByte())
    d
    • 2
    • 17
  • c

    cy

    10/09/2018, 11:18 AM
    📣 ktor
    1.0.0-alpha-1
    has been published Kotlin
    1.3.0-rc-131
    (both JVM and Native) kotlinx.coroutines
    0.30.2-eap13
    Migrated to coroutines structured concurrency (see `https://github.com/Kotlin/kotlinx.coroutines/blob/master/docs/basics.md#structured-concurrency`). Now all ktor handlers (including websocket) have relevant coroutiune scope. Please note that it is important to use with
    1.3.0-rc-131
    and not mix with incompatible coroutines versions.
    😎 2
    🎉 22
    👏 4
    d
    l
    g
    • 4
    • 29
  • o

    orangy

    10/09/2018, 1:25 PM
    📣 📣 Pretty please try the
    alpha
    build as soon as possible. We will stop
    0.9.x
    series and will not support Kotlin 1.2 very soon (because of coroutines). And release of Ktor 1.0 will go forward only with Kotlin 1.3.
    h
    • 2
    • 1
  • m

    mp

    10/09/2018, 4:16 PM
    To try the alpha, so far I have: - Updated ktor dependency version - Added the repo
    maven { url '<https://dl.bintray.com/kotlin/kotlin-eap>' }
    - Specified the kotlin version on the stdlib dependency (instead of letting the 1.2.71 plugin set it) - Specified
    kotlin-reflect
    dependency to set matching version (transitive dependency from
    jackson-module-kotlin
    ) - Changed imports for coroutine types - Also in gradle, added languageVersion and apiVersion:
    compileKotlin {
        kotlinOptions {
          jvmTarget = "1.8"
          languageVersion = "1.3"
          apiVersion = "1.3"
        }
      }
      compileTestKotlin {
        kotlinOptions {
          jvmTarget = "1.8"
          languageVersion = "1.3"
          apiVersion = "1.3"
        }
      }
    With that, I get:
    w: Language version 1.3 is experimental, there are no backwards compatibility guarantees for new language and library features
    and
    e: java.lang.IllegalStateException: Backend Internal error: Exception during code generation
    Cause: Back-end (JVM) Internal error: Error type encountered: [ERROR : For SuccessOrFailure] (ErrorType).
    Cause: Error type encountered: [ERROR : For SuccessOrFailure] (ErrorType).
    File being compiled at position: (28,42) in /home/mbp/dev/.../Foo.kt
    The root cause was thrown at: KotlinTypeMapper.java:114
    File being compiled at position: file:///home/mbp/dev/.../Foo.kt
    The root cause was thrown at: ExpressionCodegen.java:320
            at org.jetbrains.kotlin.codegen.CompilationErrorHandler.lambda$static$0(CompilationErrorHandler.java:24)
            at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:74)
            at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generatePackage(CodegenFactory.kt:97)
            at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generateModule(CodegenFactory.kt:68)
            at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.doGenerateFiles(KotlinCodegenFacade.java:47)
            at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:39)
    Am I missing a step?
    e
    c
    d
    • 4
    • 21
  • j

    Jonas Bark

    10/09/2018, 6:05 PM
    Can someone confirm my train of thoughts? according to https://ktor.io/clients/http-client/engines.html#okhttp in a multiplatform environment in order to support e.g. SSL certificate pinning or ignoring SSL altogether I would use: - Android: HttpClient using OkHttp engine with its configuration options - iOS: as there's no options available write my own engine (or even better, create a pull request)
    d
    • 2
    • 6
  • m

    mp

    10/09/2018, 6:28 PM
    ktor-1.0.0-alpha-1 quirk: I have an endpoint that throws an exception (my own
    ResourceNotFoundException
    ) that is handled by an exception handler to respond with a 404, and there's a test that this works using
    withTestApplication
    . On ktor-1.0.0-alpha-1, the test fails, seemingly because the exception bubbles up to the test itself. Interestingly, if I alter the logic to
    throw RNFE()
    directly inside the scope provided by the route (
    get("/foo")
    ), everything seems okay: the exception is thrown, handled, and responded to correctly, without crashing the test. However, in practice I have to use some blocking i/o, so I have:
    val stuff = async(ioDispatcher) {
        // blocking i/o that can throw RNFE
    }.await()
    and in that configuration, the exception crashes the test. I can see from logging that it is getting to the exception handler as well. Did I screw up structured coroutines (
    async
    is called on the
    CoroutineScope
    from
    get()
    , not global), or is this a bug in the
    TestEngine
    or something?
    • 1
    • 1
  • p

    peekandpoke

    10/09/2018, 9:41 PM
    Hi there! Simple question: How do I get an instance of a Logger? (When I do not have access to the "application.environment" or when I do not want to use the root logger)
    s
    • 2
    • 2
  • a

    alex009

    10/09/2018, 9:42 PM
    ktor-1.0.0-alpha-1 on ios throw exception on HttpClient initialization:
    #1	0x0000000105008340 in ThrowException ()
    #2	0x0000000105019b92 in kfun:kotlinx.io.charsets.Charset.Companion.forName(kotlin.String)kotlinx.io.charsets.Charset at /opt/teamcity-agent/work/22e3a7db6b861ba7/kotlinx-io-native/src/main/kotlin/kotlinx/io/charsets/CharsetNative.kt:20
    #3	0x00000001050d2082 in kfun:io.ktor.client.response.HttpResponseConfig.<init>()io.ktor.client.response.HttpResponseConfig at /opt/teamcity-agent/work/a85294440dc5c6e/ktor-client/ktor-client-core/src/io/ktor/client/response/HttpResponseConfig.kt:9
    #4	0x00000001050d1fa4 in kfun:io.ktor.client.engine.HttpClientEngineConfig.<init>()io.ktor.client.engine.HttpClientEngineConfig at /opt/teamcity-agent/work/a85294440dc5c6e/ktor-client/ktor-client-core/src/io/ktor/client/engine/HttpClientEngineConfig.kt:32
    #5	0x00000001050d7e25 in kfun:io.ktor.client.engine.ios.Ios.create(kotlin.Function1<io.ktor.client.engine.HttpClientEngineConfig,kotlin.Unit>)io.ktor.client.engine.HttpClientEngine at /opt/teamcity-agent/work/a85294440dc5c6e:1
    #6	0x00000001050c4083 in kfun:io.ktor.client.HttpClient(io.ktor.client.engine.HttpClientEngineFactory<#GENERIC_io.ktor.client.engine.HttpClientEngineConfig>;kotlin.Boolean;kotlin.Function1<io.ktor.client.HttpClientConfig<#GENERIC_io.ktor.client.engine.HttpClientEngineConfig>,kotlin.Unit>)Generic at /opt/teamcity-agent/work/a85294440dc5c6e/ktor-client/ktor-client-core/src/io/ktor/client/HttpClient.kt:29
    #7	0x00000001050c3f2f in kfun:io.ktor.client.HttpClient(kotlin.Boolean;kotlin.Function1<io.ktor.client.HttpClientConfig<#STAR>,kotlin.Unit>)io.ktor.client.HttpClient at /opt/teamcity-agent/work/a85294440dc5c6e/ktor-client/ktor-client-core/ktor-client-core-ios/src/io/ktor/client/HttpClientIos.kt:8
    #8	0x00000001050cfb1a in kfun:io.ktor.client.HttpClient$default(kotlin.Boolean;kotlin.Function1<io.ktor.client.HttpClientConfig<#STAR>,kotlin.Unit>;kotlin.Int)io.ktor.client.HttpClient at /opt/teamcity-agent/work/a85294440dc5c6e/ktor-client/ktor-client-core/ktor-client-core-ios/src/io/ktor/client/HttpClientIos.kt:5
    e
    • 2
    • 11
  • y

    Yann Zaoui

    10/10/2018, 4:51 AM
    Hey guys! How are you enforcing required parameters when receiving JSON objects? I'm using Gson content negotation, and initially expected
    ContentTransformationException
    when receiving my custom parameters class with missing fields, but instead Gson is assigning `0`/`null` to missing fields, so no exception is thrown. Jackson seems to have a
    @JsonProperty(required = true)
    annotation, but I'd rather not repeat that everywhere if there's a better solution.
    g
    • 2
    • 7
  • v

    voddan

    10/10/2018, 11:26 AM
    Hi! I started getting deprecation warnings when using Ktor on random functions that are not themselves deprecated:
    get(...) is deprecated. Experimental coroutines support will be dropped in 1.4
    in the simpliest code like
    routing {
                get("/") {
                    call.respondText("Hello World!", ContentType.Text.Plain)
                }
                get("/demo") {
                    call.respondText("HELLO WORLD!")
                }
            }
    How do I get rid of those?
    c
    e
    d
    • 4
    • 24
  • o

    otakusenpai

    10/10/2018, 12:17 PM
    Can anyone tell me the correct usage of this command in Raw Sockets
    input.read { byteBuffer }
    Where input is a ByteReadChannel object ?
    c
    d
    • 3
    • 23
  • s

    serebit

    10/10/2018, 5:57 PM
    Ktor works great so far, for HTTP requests at least. But I'm having an issue with the websockets in creating a connection to the Discord API servers. Using the same headers and parameters for both Ktor's websocket library and Http4k's nv-websockets, only Http4k manages to create the connection, while Ktor sends an invalid request (403).
    d
    • 2
    • 62
  • o

    otakusenpai

    10/10/2018, 8:45 PM
    suspend fun read(min: Int = 1, consumer: (ByteBuffer) -> Unit)
    I'm trying to implement a usage of this function but I'm getting type mismatch error Required: (ByteBuffer) -> Unit Found: ByteBuffer! Can someone give me an example or link to a code that uses (Int/String/Any) -> Unit ?
    s
    • 2
    • 2
  • o

    otakusenpai

    10/11/2018, 12:28 AM
    override suspend fun receiveData(): String? = coroutineScope {
            var data: String? = null
            try {
                // 512 here is the MAX size of a IRC message
                val bbToString = { bb: ByteBuffer ->
                    try {
                        var decoder = StandardCharsets.US_ASCII.newDecoder()
                        var charBuffer = decoder.decode(bb)
                        data = charBuffer.toString()
                    } catch(e: Throwable) {
                        throw e
                    }
                }
                input.read{ byteBuffer: ByteBuffer -> bbToString(byteBuffer) }
                if(data == null) {
                    throw Exception("BasicConnection.kt: Didn't receive data from connection!")
                }
                println("Data size = ${data?.length}")
            } catch(e: Throwable) {
                e.printStackTrace()
            }
            data
        }
    I tried using this function call to receive data from the irc server, but it seems the input is receiving null after sometime... How do I be sure that it is not my net speed(which is very slow) that is causing this drop in connection? Is it the function call's approach instead, for exampleand if so, how can it be improved?
    d
    • 2
    • 1
  • d

    Dias

    10/11/2018, 8:59 AM
    Hey, is it bad idea to send http request while sending another http request? My use case: we add an auth token for each request within our system, which we need to update after it expires. I thought I would make a feature that intercept calls and adds auth token, but I also need update token periodically so I thought I could do it from within the interceptor, since I have the http client available there. But I feel like it's a horrible idea :P
    g
    • 2
    • 8
  • a

    Andrey Z.

    10/11/2018, 12:06 PM
    Hi, I just started to use ktor websockets and I have a little comment about it. I want to broadcast a frame to all connected clients, but I didn't find a convenient way to do it with the current API. For now I have to make a class that tracks all active sessions and send frames via that class. I just want to say it would be a good feature (if I didn't miss anything)
    d
    c
    • 3
    • 9
  • m

    Marc Knaup

    10/11/2018, 1:42 PM
    Is there any guide on what DevelopmentEngine to use for what purpose?
    d
    • 2
    • 1
  • v

    voddan

    10/11/2018, 3:35 PM
    Has someone compared Ktor and ExpressJS? Their approaches seem to be very similar.
    o
    e
    • 3
    • 4
  • e

    enleur

    10/11/2018, 4:25 PM
    Ktor on netty is fast, but still there is overhead and it’s twice slower than flat netty according to benchmarks https://www.techempower.com/benchmarks/#section=test&amp;runid=a0d6e357-e8e3-4a5b-9ef0-6175ed824b20&amp;hw=ph&amp;test=json&amp;l=xan9tr-1 Are you going to improve performance and reduce overhead? And ktor-cio shows poor performance, x5 slower than ktor-netty, isn’t it supposed to be faster?
    o
    f
    • 3
    • 8
  • m

    mp

    10/11/2018, 10:25 PM
    The exception mapping issue I described a day or two ago is still present in -alpha-2. I made a simple test case: https://bitbucket.org/marshallpierce/ktor-exception-handler-repro/src/master/
    b
    • 2
    • 4
  • o

    otakusenpai

    10/12/2018, 9:37 AM
    https://github.com/OtakuSenpai/Ktor_TestBot Can someone help me with this program? Getting errors whatever I try
    d
    • 2
    • 8
  • j

    jasoet

    10/12/2018, 10:48 AM
    import io.ktor.client.features.json.JsonFeature
    is somehow not recognized.
    e
    • 2
    • 9
  • d

    Dias

    10/12/2018, 1:25 PM
    Hey, I cannot find the way to configure MockEngine for testing http client. I want to use features along with a mock engine, but I cannot find the way to do it. this way:
    HttpClient(MockEngine) {
                install(JWTAuth) {
    
                }
            }
    doesn't allow to set up the engine itself. While setting up MockEngine and passing the instance to http client doesn't allow me to install the feature
    e
    • 2
    • 6
  • r

    Renann

    10/12/2018, 2:14 PM
    does it make sense to use ktor with gRPC? do you guys have a good example on how to use gRPC + ktor?
    e
    • 2
    • 2
Powered by Linen
Title
r

Renann

10/12/2018, 2:14 PM
does it make sense to use ktor with gRPC? do you guys have a good example on how to use gRPC + ktor?
e

enleur

10/12/2018, 2:16 PM
why do you need Ktor for gRPC and vice versa?
r

Renann

10/12/2018, 2:33 PM
@enleur I don't need ktor for gRPC I was just wondering if it makes sense to use them together, 'cause for example with spring I'm able to take advantage of dependency injection And I'd like to take advantage of ktor as well, if it makes sense
View count: 6