在python的socket中是否有类似recv\u until()的函数?

2024-06-26 13:25:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图通过TCP-IP从数据接受器DT85接收数据,但接收到的数据并不是DT85应该发送的所有内容。你知道吗

延迟解决了我的问题,但我认为使用延迟不是一个好主意,因为如果接收消息的时间比延迟时间长,我会再次出现问题。有什么功能可以很好地解决这个问题吗?你知道吗

try:
    s.send((messageToSend.encode()))
    debug(f"Sending message: {messageToSend}")
except:
    debug("Sending message failed \n")

sleep(4)

try:
    data = s.recv(BUFFER_SIZE)
    debug(f"Received data: {data} \n")
    debug(f"{data.decode('utf-8')} {TERMINATOR}")
except:
    debug("Receiving data failed \n")
    data = ""

Tags: 数据debugip内容messagedatatcptry