Echo server: Difference between revisions

→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details
(Added Kotlin)
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 1,337:
 
import java.io.BufferedReader
import java.io.PrintWriter
import java.io.InputStreamReader
import java.io.PrintWriter
import java.net.ServerSocket
import java.net.Socket
 
class ClientHandler(private val clientSocket: Socket): Runnable {
private val connectionId: Int
 
Line 1,354:
val br = BufferedReader(InputStreamReader(clientSocket.inputStream))
while (true) {
val line = br.readLine() ?: break
if (line == null) break
println("Received: $line")
pw.write("$line\n")
Line 1,364 ⟶ 1,363:
pw.close()
clientSocket.close()
println("Closing connection, #$connectionId")
}
 
Line 1,370 ⟶ 1,369:
var numConnections = 0
}
}
 
fun main(args: Array<String>) {
Line 1,379 ⟶ 1,378:
}
}
finally {
serverSocket.close()
println("Closing server socket")