AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-600637

Cenkoloji's questions

Martin Hope
Cenkoloji
Asked: 2021-04-28 15:19:42 +0800 CST

Python 套接字:Linux 中的 TCP 错误,而相同的程序在 Windows10 上运行良好

  • -1

我正在尝试使用 python 套接字通过 TCP/IP 与商用电源设备进行通信。

我尝试在同一网络接口上同时使用虚拟 linux(centos8stream)和虚拟 windows10,它们都在同一台物理计算机上运行。两者都有python3.9。

我想象 tcp/ip 套接字在两个操作系统中都可以正常工作,但我只在 linux 中遇到了一些通信问题:

  • 几次尝试后,发送和接收之间的延迟变得更长(2 秒而不是 0.14 秒)
  • 有时我会超时,根本无法与设备通信。

我让 Wireshark 在两个操作系统中运行:

  • 在 Windows 中没有异常消息(很少有 TCP 重传)
  • 在 linux 中,一段时间后(或有时立即)wireshark 会被 TCP Dup Ack、TCP Fast Retransmission 和 TCP Spurious Retransmissions 淹没。

我的问题:

  1. 差异的根源可能是什么?我可以尝试任何套接字选项吗?
  2. 有没有办法比较linux和windows10中的网络参数?

连续读取设备标识的示例程序:

import socket
from time import sleep,time
HOST = '10.27.4.50'
PORT = 4444

#Create object and open the connection
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((HOST, PORT))

client.settimeout(5)

# Read identification
message=(b'*IDN?\r\n')

for i in range(5):
    start_time = time()
    client.sendall(message)
    rep=client.recv(1024)
    print("Trial {}, delay: {} seconds ".format(i,time() - start_time))
    sleep(1)

client.close()

视窗:

Trial 0, delay: 0.17121100425720215 seconds
Trial 1, delay: 0.10957813262939453 seconds
Trial 2, delay: 0.17148327827453613 seconds
Trial 3, delay: 0.13976049423217773 seconds
Trial 4, delay: 0.14109373092651367 seconds

linux(看到最后一条消息需要更长的时间才能收到响应,这对应于 TCP 错误的开始)

Trial 0, delay: 0.15080499649 seconds
Trial 1, delay: 0.143104076385 seconds
Trial 2, delay: 0.170531988144 seconds
Trial 3, delay: 0.183187961578 seconds
Trial 4, delay: 2.0480530262 seconds

注意:我还尝试了一台物理 linux 机器,也有同样的问题。

python tcpip wireshark socket
  • 1 个回答
  • 457 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve