简体   繁体   English

尝试将套接字连接到不同网络中的服务器会引发 WinError 10060

[英]Trying to connect socket to server in different networks raises WinError 10060

I am trying to establish a socket connection, therefore I coded and tried this example code with server.py and client.py:我正在尝试建立套接字连接,因此我使用 server.py 和 client.py 编写并尝试了此示例代码:

server.py:服务器.py:

import socket

port = 5674
ip = socket.gethostbyname(socket.gethostname())

s = socket.socket()
s.bind((ip, port))
s.listen(2)
print('Server is ready')

while True:
    client, address = s.accept()
    print('New connection to {}'.format(address))
    client.send('You are connected to the server!'.encode('utf-8'))

client.py:客户端.py:

import socket

ip = ''  # enter ip address of server
port = 5674

s = socket.socket()
s.connect((ip, port))

msg = s.recv(1024).decode('utf-8')
print(msg)

Trying to run this on one machine will work absolutely fine.尝试在一台机器上运行它绝对可以正常工作。

Running on different machines in different networks will give the following error-message in client.py:在不同网络的不同机器上运行会在 client.py 中给出以下错误消息:

Traceback (most recent call last): File "D:/Python/01programs/SocketTest/client.py", line 7, in s.connect((ip, port)) TimeoutError: [WinError 10060] Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer >bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da >der verbundene Host nicht reagiert hat回溯(最近一次调用):文件“D:/Python/01programs/SocketTest/client.py”,第 7 行,在 s.connect((ip, port)) TimeoutError: [WinError 10060] Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer >bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da >der verbundene Host nicht reagiert hat

-> shortened in English: try to connect failed because the connected host did not respond in time -> 英文缩写:尝试连接失败,因为连接的主机没有及时响应

What is going wrong with this socket connection?这个套接字连接出了什么问题? I would say it seems like client is not able to find server and is not able to connect because of this.我会说客户端似乎无法找到服务器并且因此无法连接。

What part is wrong and how to fix?哪个部分有问题,如何修复? Thanks for help!感谢帮助!

PS: I already read many questions related to this problem but none of them seemed to help in my case. PS:我已经阅读了许多与此问题相关的问题,但似乎没有一个对我的情况有帮助。

If you trying to accesses your server not from the same host, you can't.如果您尝试访问的服务器不是来自同一主机,则无法访问。 you need to run the server not in local-host mode, change the server ip bind to "0.0.0.0" and it should work.您需要不在本地主机模式下运行服务器,将服务器 ip 绑定更改为“0.0.0.0”,它应该可以工作。

我正在尝试使用显示 URLError 的 seaborn 加载数据集: <urlopen error [winerror 10060]< div><div id="text_translate"><p> df = sns.load_dataset("提示")</p><p> 我正在尝试使用显示 URLError 的 seaborn 加载数据集:</p><p> 几秒钟后抛出此错误</p><pre>TimeoutError Traceback (most recent call last) File ~\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py:1348, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args) 1347 try: -> 1348 h.request(req.get_method(), req.selector, req.data, headers, 1349 encode_chunked=req.has_header('Transfer-encoding')) 1350 except OSError as err: # timeout error File ~\AppData\Local\Programs\Python\Python311\Lib\http\client.py:1282, in HTTPConnection.request(self, method, url, body, headers, encode_chunked) 1281 """Send a complete request to the server.""" -> 1282 self._send_request(method, url, body, headers, encode_chunked) File ~\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py:241, in urlretrieve(url, filename, reporthook, data) 224 """ 225 Retrieve a URL into a temporary location on disk. 226 (...) 237 data file as well as the resulting HTTPMessage object. 238 """ 239 url_type, path = _splittype(url) --> 241 with contextlib.closing(urlopen(url, data)) as fp: 242 headers = fp.info() 244 # Just return the local path and the "headers" for file:// 245 # URLs. No sense in performing a copy unless requested. URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond></pre><p> 我尝试更改 inte.net 连接,还尝试取消选中 LAN 设置中的代理服务器</p></div></urlopen> - I am trying to load dataset using seaborn showing URLError: <urlopen error [WinError 10060]

暂无
暂无

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

相关问题 WinError 10060 尝试使用 Python PySFTP 模块连接到远程服务器时出错 - WinError 10060 Error when trying to connect to remote server using Python PySFTP module WinError 10060 python 通过路由器连接 python 插座 - WinError 10060 python connect python socket through router Python 套接字在其他计算机上超时。 超时错误:[WinError 10060] - Python socket timing out on other computer. TimeoutError: [WinError 10060] 使用 socket python 连接不同网络上的两台计算机 - Connect two computers on different networks using socket python Python ftplib WinError 10060 - Python ftplib WinError 10060 超时错误:[WinError 10060]: - TimeoutError: [WinError 10060] : 当尝试使用我的外部IP地址从本地客户端连接到我的服务器时,出现Errno 10060 - Errno 10060 when trying to connect from a local client to the my server using my external ip adress 套接字-简单服务器/客户端-socket.error:[Errno 10060] - Socket - Simple Server/Client - socket.error: [Errno 10060] python 套接字编程:尝试连接服务器时出错 - python socket programming : error trying to connect to server 我正在尝试使用显示 URLError 的 seaborn 加载数据集: <urlopen error [winerror 10060]< div><div id="text_translate"><p> df = sns.load_dataset("提示")</p><p> 我正在尝试使用显示 URLError 的 seaborn 加载数据集:</p><p> 几秒钟后抛出此错误</p><pre>TimeoutError Traceback (most recent call last) File ~\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py:1348, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args) 1347 try: -> 1348 h.request(req.get_method(), req.selector, req.data, headers, 1349 encode_chunked=req.has_header('Transfer-encoding')) 1350 except OSError as err: # timeout error File ~\AppData\Local\Programs\Python\Python311\Lib\http\client.py:1282, in HTTPConnection.request(self, method, url, body, headers, encode_chunked) 1281 """Send a complete request to the server.""" -> 1282 self._send_request(method, url, body, headers, encode_chunked) File ~\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py:241, in urlretrieve(url, filename, reporthook, data) 224 """ 225 Retrieve a URL into a temporary location on disk. 226 (...) 237 data file as well as the resulting HTTPMessage object. 238 """ 239 url_type, path = _splittype(url) --> 241 with contextlib.closing(urlopen(url, data)) as fp: 242 headers = fp.info() 244 # Just return the local path and the "headers" for file:// 245 # URLs. No sense in performing a copy unless requested. URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond></pre><p> 我尝试更改 inte.net 连接,还尝试取消选中 LAN 设置中的代理服务器</p></div></urlopen> - I am trying to load dataset using seaborn showing URLError: <urlopen error [WinError 10060]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM