Can anyone tell me the correct usage of this comma...
# ktor
o
Can anyone tell me the correct usage of this command in Raw Sockets
Copy code
input.read { byteBuffer }
Where input is a ByteReadChannel object ?
The problem is that when i instantiate it with a size of 512, the data from the println shows the size as 512 but the contents of the data isnull
Copy code
var byteBuffer = ByteBuffer.wrap(ByteArray(512))
            input.read { byteBuffer }
            data = String(byteBuffer.array(), Charset.forName("ASCII"))
            println("Data size = ${data.length}")
I changed the code to this
Copy code
var byteBuffer = ByteBuffer.wrap(ByteArray(512))
            val bbToString = { data = String(byteBuffer.array(), Charset.forName("ASCII")) }
            input.read { byteBuffer -> bbToString }
But its giving me this error
Copy code
java.lang.Exception: BasicConnection.kt: Didn't receive data from connection!
	at com.github.otakusenpai.testbot.connection.BasicConnection$receiveData$1.doResume(BasicConnection.kt:83)
	at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:42)
	at kotlinx.coroutines.experimental.DispatchedTask$DefaultImpls.run(Dispatched.kt:168)
	at kotlinx.coroutines.experimental.DispatchedContinuation.run(Dispatched.kt:13)
	at kotlinx.coroutines.experimental.EventLoopBase.processNextEvent(EventLoop.kt:166)
	at kotlinx.coroutines.experimental.BlockingCoroutine.joinBlocking(Builders.kt:69)
	at kotlinx.coroutines.experimental.BuildersKt__BuildersKt.runBlocking(Builders.kt:45)
	at kotlinx.coroutines.experimental.BuildersKt.runBlocking(Unknown Source)
	at kotlinx.coroutines.experimental.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:35)
	at kotlinx.coroutines.experimental.BuildersKt.runBlocking$default(Unknown Source)
	at com.github.otakusenpai.testbot.connection.BasicConnection.receiveData(BasicConnection.kt:73)
	at com.github.otakusenpai.testbot.MainKt.main(main.kt:89)
Received data: null
c
Don't get,
read{ }
lambda has
Unit
return type so I don't get what are you trying to do
To read bytes to a byte buffer use
readAvailable
or
readFully
o
ok
I'll try
c
Please read kdoc for
read
if you are sure that you really need exactly this function
o
where is the link ?
c
Can't you simply navigate it it?
o
no just the link to kdoc, i was previously reading the ktor.io docs
c
Why not? Doesn't it work if you Ctrl-click on it?
It should work out of the box
if not, you can read it here
<https://github.com/Kotlin/kotlinx-io/blob/eap13/kotlinx-coroutines-io/kotlinx-coroutines-io-jvm/src/main/kotlin/kotlinx/coroutines/experimental/io/ByteReadChannelJVM.kt#L152>
o
I just want to know what this kdocs is that you speak about
c
kdoc is just like javadoc but different syntax (markdown instead of html)
o
ok so where can i download this kdoc for ktor ?
c
IDEA usually shows it in the documentation popup but it only work if you have downloaded sources
o
nvm found it
c
yes, you can browse it here but it is not yet published for 1.0.0-alpha-* yet
d
https://api.ktor.io/1.0.0-alpha-1/ Still that documentation is from kotlinx-io so not included here