# TestServer.py from tcpcom import TCPClient from easygui import msgbox # Standard Python with easygui def onStateChanged(state, msg): print state, "-", msg host = "localhost" port = 5000 client = TCPClient(host, port, stateChanged=onStateChanged, isVerbose=True) success = client.connect() if success: msgbox("Client connected. OK to disconnect", "Test Client") # Standard Python client.sendMessage("Test Client says Hello To You!") client.disconnect() else: msgbox("Client connection failed. OK to quit", "Test Client") # Standard Python
# RaspEasyClient.pc from tcpcom import TCPClient #from easygui import msgbox, enterbox def onStateChanged(state, msg): if state == "CONNECTING": print "Client:-- Waiting for connection..." elif state == "CONNECTED": print "Client:-- Connection estabished." elif state == "MESSAGE": print "Client:-- Received data:", msg port = 5000 # IP port host = "192.168.1.106" client = TCPClient(host, port, stateChanged=onStateChanged) rc = client.connect() if rc: msgDlg("OK to terminate") # TigerJython # msgbox("Button client running. OK to stop","Button Client") client.disconnect()
setStatusText("Trying to connect...") if state == TCPClient.CONNECTION_FAILED: setStatusText("Connection failed") if state == TCPClient.CONNECTED: setStatusText("Connection established") if state == TCPClient.MESSAGE: if "setPos" in msg: exec(msg) xPrey = getX() yPrey = getY() drawImage("sprites/mouse.gif") startTime = time.time() isMouseEnabled = True def onCloseClicked(): client.disconnect() dispose() makeTurtle(mouseHit = onMouseHit, closeClicked = onCloseClicked) addStatusBar(30) hideTurtle() isMouseEnabled = False setCustomCursor("sprites/cathead.png") host = "localhost" port = 5000 client = TCPClient(host, port, stateChanged = onStateChanged) client.connect()