From 9b90fe370b51c88a7a08eb8fb146da61fae2b302 Mon Sep 17 00:00:00 2001 From: sergeych Date: Thu, 9 Apr 2026 17:11:30 +0300 Subject: [PATCH] improved tcpserver.lyng sample --- examples/tcpserver.lyng | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/examples/tcpserver.lyng b/examples/tcpserver.lyng index 2e14213..c4d14c9 100644 --- a/examples/tcpserver.lyng +++ b/examples/tcpserver.lyng @@ -5,28 +5,22 @@ val clientCount = 1000 val server = Net.tcpListen(0, host, clientCount, true) as TcpServer val port = server.localAddress().port -fun payloadFor(index: Int): String { - "$index:${Random.nextInt()}:${Random.nextInt()}" -} - -fun handleClient(client: TcpSocket) { - try { - val source = client.readLine() - if( source != null ) { - client.writeUtf8("pong: $source\n") - client.flush() - } - } finally { - client.close() - } -} +fun payloadFor(index: Int) = "$index:${Random.nextInt()}:${Random.nextInt()}" launch { try { - for( i in 0.. }.joinAll() assertEquals(clientCount, replies.size) - -val summary = "OK: $clientCount concurrent tcp clients" -println(summary) -summary +println("OK: $clientCount concurrent tcp clients")