使用Groovy进行Socket编程之-字节数组版
服务端代码:
客户端调用代码:import java.net.Socketclass Test {static main(args) {def sw = new StringWriter()def xml = new groovy.xml.MarkupBuilder(sw)xml.langs(type:"current", count:3, mainstream:true){ language(flavor:"static", version:"1.5", "Java") language(flavor:"dynamic", version:"1.6.0", "Groovy") language(flavor:"dynamic", version:"1.9", "JavaScript") language(flavor:"测试", version:"2.2", "闲得蛋疼")}def s = new Socket("10.14.131.114", 6666);s.withStreams { input, output ->output << sw.toString()byte[] msgBody = new byte[2000];input.read(msgBody, 0, 2000);def msg = new String(msgBody, 'UTF8').trim()println "${msg.trim()}"}}}