Created
May 20, 2014 13:02
-
-
Save mgdelacroix/2036ab7c653fa9d7c045 to your computer and use it in GitHub Desktop.
Simple Groovy client-server comunication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def socket = new Socket('localhost', 5000) | |
socket.withStreams { input, output -> | |
println input.newReader().readLine() | |
output << 'Imma socket' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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