1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
try {
  host = args[0] 
  port = args[1].toInteger()
} catch (e) {
  println "usage: groovy ${this.class.name} host port"
  System.exit 1
}

new Socket(host, port).withStreams { is, os ->
  dis = new DataInputStream(is)
  buf = new byte[1024]
  while ((len = System.in.read(buf)) >= 0) {
    os.write(buf, 0, len)
    dis.readFully(buf, 0, len)
    System.out.write(buf, 0, len)
  }
}