好的,所以我读了很多问题,但无法弄清楚。我从我的 Android 应用程序收到的数据遇到问题。基本上我想控制伺服。该代码有效,但应用程序发送到服务器的数据是在单独的行中接收的。是的,我知道我需要使用缓冲区,我进行了一些研究,但找不到向我的代码添加缓冲区的方法。此外,我认为我不需要显示我的 Java 代码,因为它只是从按钮点击发送的基本命令(向上、向下等字符串)。
...Python Code(Server)...
ctrCmd = ['Up','Down', 'ON', 'OFF']
...
...
while True:
print ("Waiting for connection")
tcpCliSock,addr = tcpSerSock.accept()
print ("...connected from :", addr)
try:
while True:
data = ''
data = tcpCliSock.recv(BUFSIZE).decode()
print("This",data)
if not data:
print ("No Data",data)
break
if data == ctrCmd[0]:
print("I am here")
Servomotor.ServoUp()
print ("Increase: ",Servomotor.cur_X)
#tcpCliSock.send("Servo Increases".encode())
if data == ctrCmd[1]:
Servomotor.ServoDown()
print ("Decrease: ",Servomotor.cur_X)
#tcpCliSock.send("Servo Decreases".encode())
if data == ctrCmd[2]:
Servomotor.ledOn()
print ("Led On")
#tcpCliSock.send("Led On".encode())
if data == ctrCmd[3]:
Servomotor.ledOff()
print ("Led Off")
# tcpCliSock.send("Led Off".encode())
except KeyboardInterrupt:
Servomotor.close()
GPIO.cleanup()
tcpSerSock.close();
精慕HU
陪伴而非守候
呼啦一阵风
相关分类