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
import java.net.Socket | |
import java.nio.charset.Charset | |
def getBytes={istr,n->def r=new byte[n];istr.read(r,0,n);r} | |
def putUInt = { o,i -> | |
def b= [ ( i & 0x000000FF ) >> 0 , | |
( i & 0x0000FF00 ) >> 8 , | |
( i & 0x00FF0000 ) >> 16 , | |
( i & 0xFF000000 ) >> 24 ] as byte[] | |
o.write(b) } | |
def putStr = { o,str -> | |
def b=str.getBytes(Charset.forName('US-ASCII')) | |
o.write(b) } | |
def getUInt={i-> | |
def v=getBytes(i,4) | |
def r=0 | |
for(int j=0;j<4;++j){r=r|(v[j]<<(8*j))} | |
r} | |
def getStr={i,l-> | |
new String(getBytes(i,l),Charset.forName('US-ASCII'))} | |
def flush={s->s.flush()} | |
def sock=null | |
try { | |
def t0=new Date().time | |
sock=new Socket("127.0.0.1",3001) | |
sock.withStreams{i,o-> | |
1000.times { e -> | |
println("$e") | |
putUInt(o,11) | |
putStr(o,"list_themes") | |
flush(o) | |
def n | |
n=getUInt(i) | |
n.times { | |
def m,s | |
m=getUInt(i) | |
s=getStr(i,m) | |
println("$s") | |
} | |
} | |
} | |
println("elapsed ms ${new Date().time - t0}") | |
}finally{ | |
try{sock.close()}catch(Exception e){e.printStackTrace(System.err)} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment