// ... def address = InetAddress.getByName("127.0.0.1") while (true) { if (threadCount < MAX_THREADS) { Thread.start() { // ... def socket = new Socket(address, ClientServer.PORT) socket.withStreams { input, output -> // client-server code } // ... } } Thread.currentThread().sleep(100) }