The blog describes the basic principles:
http://programmingitch.blogspot.co.uk/2010/04/groovy-sockets-example.html
import java.net.ServerSocket def server = new ServerSocket(4444) while(true) { server.accept { socket -> println "processing new connection..." socket.withStreams { input, output -> def reader = input.newReader() def buffer = reader.readLine() println "server received: $buffer" now = new Date() output << "echo-response($now): " + buffer + "\n" } println "processing/thread complete." } }
This gives you basic socket connections and I / O streams for the connected client. You will have to configure this to track multiple clients and send (send to all connected users) any messages from the server.
source share