简体   繁体   English

Python3 socket.recv 没有确认

[英]Python3 socket.recv without acking

My python program is talking to a device that will delay the conversation by an entire second each time it receives an ack to a push/ack.我的 python 程序正在与一个设备交谈,该设备每次收到推送/确认的确认时都会将对话延迟一整秒。 The conversation is hundreds if not thousands of messages long, so naturally I would like a way around this.对话长达数百甚至数千条消息,所以我自然想要一种解决方法。

Is there a way to open a connection to my device, keep it open with the intention to send to it but don't ack messages I am receiving back with socket.recv()?有没有办法打开到我的设备的连接,让它保持打开状态并打算发送给它,但不要确认我用 socket.recv() 收到的消息?

import socket

s = socket.socket()
s.bind(('', xxxxx))
s.connect(('x.x.x.x', xxxxx))

while True:
    try:
        msg = input()
        if 'exit' in msg:
            data = b'I am done now, bye'
            s.send(data)
            data = s.recv(2048)
            print('recieved final message: ' + str(data))
            break
        msg = msg.encode()
        s.send(msg)
        print('sent message: ' + str(msg))
        data = s.recv(2048)
        print('received message: ' + str(data))
        print()
        data = ''
    except Exception as e:
        print(e)

s.close()

ACKs are essential to send when data are received.在接收到数据时发送 ACK 是必不可少的。 Otherwise the sender will simply assume that the data were not received and will try to resent the data.否则,发送方将简单地假设未收到数据并尝试重新发送数据。 This will essentially stall the communication since only a (initially small) window of non-acked data is acceptable.由于只有一个(最初很小的)未确认数据的窗口是可以接受的,因此这基本上会停止通信。 Therefore it makes no sense to create such a connection and that's why there is no way to do it.因此,创建这样的连接是没有意义的,这就是为什么没有办法做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM