python套接字中是否有类似于recv_until()的函数?

时间:2018-12-21 19:15:46

标签: python python-3.x tcp-ip

我正在尝试通过TCP-IP从DataTaker 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 = ""

0 个答案:

没有答案