Skip to content

Instantly share code, notes, and snippets.

@mgdelacroix
Created May 20, 2014 13:02
Show Gist options
  • Save mgdelacroix/2036ab7c653fa9d7c045 to your computer and use it in GitHub Desktop.
Save mgdelacroix/2036ab7c653fa9d7c045 to your computer and use it in GitHub Desktop.
Simple Groovy client-server comunication
def socket = new Socket('localhost', 5000)
socket.withStreams { input, output ->
println input.newReader().readLine()
output << 'Imma socket'
}
def socketServer = new ServerSocket(5000)
while(true) {
socketServer.accept { socket ->
socket.withStreams { input, output ->
output << "[${new Date()}] HELLO\n"
println ">> READ: ${input.newReader().readLine()}"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment