def handle(self): # self.request is the TCP socket connected to the client client = "%s:%s" % (self.client_address[0], self.client_address[1]) print "connect({})".format(client) buf = "" cnt = 0 while(True): self.data = self.rfile.readline() if not self.data: break buf = buf + self.data if buf.endswith('\n\n'): try: pd = paramsdict(buf) pd.ack() self.wfile.write(pd._string()) except: print 'invalid message:{}'.format(buf) break; finally: cnt = cnt + 1 buf = '' print "disconnect({}); {} messages".format(client,cnt)
try: for i in range(0,999): message = 'python.set-cell\nvar:key%d\nval:%g\n\n' % (i,(i*math.pi)) print >>sys.stderr, 'sending>%s' % message, sock.sendall(message) msg = '' while not msg.endswith('\n\n'): #print >>sys.stderr, 'sock.recv ...', data = sock.recv(4096) #print >>sys.stderr, '[' + data + '] ok' if not data: break msg = msg + data; pd = paramsdict(msg) #lines = msg.rstrip('\n').split('\n') #head = lines[0]; #body = lines[1:] #hash = {}; #for i in range(0,len(body)): # pos = body[i].index(":") # key = body[i][:pos] # val = body[i][pos+1:] # hash[key] = val print >>sys.stderr, 'received>%s' % pd finally: sock.close()