otakusenpai
04/13/2018, 12:51 PMDeactivated User
04/13/2018, 1:26 PMaSocket
with a
in lower case just like in the documentation.
val socket = aSocket().tcp().connect(InetSocketAddress("127.0.0.1", 2323))
otakusenpai
04/13/2018, 1:27 PMotakusenpai
04/13/2018, 1:32 PMotakusenpai
04/13/2018, 1:32 PMDeactivated User
04/13/2018, 1:33 PMimport io.ktor.network.sockets.*
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.io.*
import java.net.*
fun main(args: Array<String>) {
runBlocking {
val server = aSocket().tcp().bind(InetSocketAddress(“127.0.0.1”, 2323))
println(“Started echo telnet server at ${server.localAddress}“)
while (true) {
val socket = server.accept()
launch {
println(“Socket accepted: ${socket.remoteAddress}“)
val input = socket.openReadChannel()
val output = socket.openWriteChannel(autoFlush = true)
try {
while (true) {
val line = input.readASCIILine()
println(“${socket.remoteAddress}: $line”)
output.writeBytes(“$line\r\n”)
}
} catch (e: Throwable) {
e.printStackTrace()
socket.close()
}
}
}
}
}
Deactivated User
04/13/2018, 1:34 PMalt+return
and select Import
to add the right imports
http://oi67.tinypic.com/1247b5x.jpg▾
otakusenpai
04/13/2018, 1:34 PMDeactivated User
04/13/2018, 1:36 PMhttp://oi65.tinypic.com/mlgtck.jpg▾
Deactivated User
04/13/2018, 1:37 PMhttp://oi68.tinypic.com/30swv2b.jpg▾
Deactivated User
04/13/2018, 1:37 PMalt+return
to specify type explicitly and see of what type a expression isotakusenpai
04/13/2018, 1:37 PMotakusenpai
04/13/2018, 1:37 PMDeactivated User
04/13/2018, 1:37 PM