pane1 = EntryPane(status) btn = ButtonEntry("Finish") pane2 = EntryPane(btn) dlg = EntryDialog(pane1, pane2) dlg.setTitle("Client Information") dlg.show() host = "localhost" port = 5000 showStatusDialog() client = TCPClient(host, port, stateChanged=onStateChanged) status.setValue("Trying to connect to " + host + ":" + str(port) + "...") time.sleep(2) rc = client.connect() if rc: time.sleep(2) n = 0 while not dlg.isDisposed(): if client.isConnected(): status.setValue("Sending: " + str(n)) time.sleep(0.5) client.sendMessage(str(n), 5) # block for max 5 s n += 1 if btn.isTouched(): dlg.dispose() time.sleep(0.5) client.disconnect() else: status.setValue("Connection failed.")
elif state == TCPClient.CONNECTED: local.setValue("Working...") remote.setValue("Connected. Working...") #host = "192.168.0.102" host = "localhost" port = 5000 client = TCPClient(host, port, stateChanged=onStateChanged) showStatusDialog() local.setValue("Trying to connect...") remote.setValue("Disconnected") locresult.setValue("(n/a)") rc = client.connect() if rc: k = 0 n = 0 startTime = time.clock() while not dlg.isDisposed() and client.isConnected(): zx = random.random() zy = random.random() if zx * zx + zy * zy < 1: k += 1 n += 1 if n % sliceSize == 0: pi = 4 * k / n t = time.clock() - startTime info = "n: %d; k: %d; pi: %f. Time: %3.1f" % (n, k, pi, t) locresult.setValue(info) client.sendMessage(str(n) + ";" + str(k)) client.disconnect()