Here's a simple python client that evaluates a single model. You may need to indent the loop, i.e. the three lines after "while True:"
import socket
model = """<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> <!DOCTYPE sodaconstructor> <model> <container width="651" height="422"/> <environment gravity="0.31443796" friction="0.05458992" springyness="0.32299763"/> <collisions surface_friction="0.1" surface_reflection="-0.75"/> <wave amplitude="0.60465115" phase="0.0015686274" speed="0.008235294"/> <settings gravitydirection="down" wavedirection="forward" autoreverse="off"/> <nodes> <mass id="m7" x="0.20344639" y="0.0" vx="7.347312E-17" vy="0.19228646"/> <mass id="m8" x="39.06419" y="34.916317" vx="-2.4770938E-14" vy="7.3158236E-14"/> <mass id="m9" x="78.87359" y="69.91241" vx="-2.687017E-14" vy="7.4260334E-14"/> <mass id="m10" x="38.851414" y="35.02552" vx="-3.4532368E-14" vy="3.8940754E-14"/> <mass id="m11" x="0.008171797" y="0.0" vx="1.7318665E-16" vy="0.19119084"/> <mass id="m12" x="76.12644" y="0.0" vx="-1.0758565E-15" vy="0.25021917"/> <mass id="m13" x="75.98091" y="0.0" vx="-3.8835794E-16" vy="0.27948648"/> </nodes> <links> <spring a="m8" b="m7" restlength="0.0"/> <spring a="m9" b="m8" restlength="0.0"/> <spring a="m10" b="m9" restlength="0.0"/> <spring a="m11" b="m10" restlength="0.0"/> <spring a="m12" b="m7" restlength="74.97434"/> <spring a="m12" b="m8" restlength="52.222485"/> <spring a="m13" b="m10" restlength="52.6637"/> <spring a="m13" b="m11" restlength="74.79381"/> <muscle a="m7" b="m9" restlength="159.0" amplitude="0.52380955" phase="0.0"/> <muscle a="m9" b="m11" restlength="159.0" amplitude="0.52380955" phase="0.5019608"/> </links> </model> """
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(('localhost', 7777)) sockfile = sock.makefile(mode='r+')
# Read and check the header header = sockfile.readline() assert header.startswith('Hello client: ') print "Connected to sodarace"
# Read and check the request request = sockfile.readline() qmark_pos = request.find('?') assert qmark_pos > 0 print "got request: ", request id = request[0:qmark_pos]
# Send the model sockfile.write(model) sockfile.flush() print "Sent model"
while True: racer = sockfile.readline() print "Received: ", racer if racer.startswith(id + '>'): break
print "Time: ", racer[racer.find('>')+1:-1]
|