python socket Windows 10连接超时 [英] python socket Windows 10 connection times out

查看:43
本文介绍了python socket Windows 10连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近将一台 Windows 计算机从 Windows 7 升级到了 Windows 10,对操作系统进行了完全干净的安装.当它运行 Windows 7 时,我们托管了几个简单的 Python 套接字服务器,以便网络上的另一台 Linux 计算机可以与 Windows 计算机上的某些驱动程序交互.该系统(将套接字服务器绑定到开放端口并侦听响应)在升级前的一年中运行良好.

We recently upgraded a windows computer to Windows 10 from Windows 7, doing a completely clean installation of the OS. When it ran Windows 7, we hosted a couple of simple python socket servers so that another Linux computer on the network could interface with certain drivers on the Windows machine. This system (of binding a socket server to an open port and listening for a response) worked perfectly for the year leading up to this upgrade.

当我们更新 Windows 机器上的操作系统时,之前在两台计算机之间建立 SOCK_STREAM 服务器连接的相同 python 脚本停止运行.当被要求连接时,连接只是超时.

When we updated the OS on the windows machine, the same python scripts that previously set up a SOCK_STREAM server connection between the two computers stopped functioning. When asked to connect, the connection simply times out.

有没有人知道任何可能影响套接字在 Windows 10 上侦听能力的更改,和/或对此问题的任何修复?在大量的挖掘中,我们没有发现明显的修复.

Does anyone know any changes that might have impacted socket's ability to listen on Windows 10, and/or any fixes to this issue? In a lot of digging we have been able to turn up no apparent fixes.

这是在每台计算机上运行的代码的基本示例.

Here is a basic example of the code being ran on each computer.

Windows 10:

Windows 10:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("XX.XX.XX.XX", XXXXX))
s.listen()
while True:
    conn, addr = s.accept() 
    try:
        conn.settimeout(3)
        data = conn.recv(1024)
    except:
        break
    if not data:break
# more code follows to process the data, etc.

在 Linux 上:

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10) # this timeout can change, and it just hangs indefinitely when removed
s.connect(("XX.XX.XX.XX",XXXXX))

上面作为一系列 X 引用的 IP 和端口可用并且不会引发任何错误.

The IP and Port referenced above as a series of X's are available and do not throw any bugs.

推荐答案

这是一个防火墙问题(就像 @yorodm 说的),所以不是 Python 代码出错,而是计算机.

This is a firewall issue (like @yorodm said), so it is not the Python code that is making the mistake, it's the computer.

我无法为 Linux 计算机提供解决方案(我假设它运行正常,防火墙允许传入连接),但我可以为 Windows 10 计算机提供.

I can't give a solution for the Linux computer (I assume that it is running correctly, with the firewall allowing incoming connections), but I can for the Windows 10 computer.

所以这是一个解决方案:

So here is a solution:

转到开始",然后启动 Cortana.输入允许应用程序通过 Windows 防火墙",然后点击Enter"键.点击更改设置"按钮,在python.exe"旁边,勾选左边的复选框,如果还没有启用,勾选python.exe右边的两个.

Go to Start, and start Cortana. Type in "Allow an app through Windows Firewall", then tap the "Enter" key. Click on the "change settings" button, and next to "python.exe", check the box to the left, and if it isn't already enabled, the two to the right of python.exe.

这篇关于python socket Windows 10连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆