简体   繁体   English

ConnectionRefusedError:[Errno 111] 笔记本电脑和树莓派之间使用 python 连接被拒绝

[英]ConnectionRefusedError: [Errno 111] Connection refused between laptop and raspberry pi using python

I am a beginner in socket communication and I wanted to test this code.我是套接字通信的初学者,我想测试这段代码。

I wrote the same code but changed the host in the server to s.gethostname() when both the client and server were on my laptop and worked normally.我编写了相同的代码,但是当客户端和服务器都在我的笔记本电脑上并且正常工作时,将服务器中的主机更改为 s.gethostname()。

server: Laptop服务器:笔记本电脑

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = ''
port = 62402
s.bind((host,port))
s.listen(5)
while True:
  clientsocket, address = s.accept()
  print(f"connection from {address} has been established!")
  clientsocket.send(bytes("Welcome to the server!","utf-8"))

client: raspberry pi客户:树莓派

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
port = 62402
s.connect((host,port))
msg = s.recv(1024)
print(msg.decode('utf-8')

Error错误

Traceback(most recent call last):
 File "/home/pi/Desktop/testting/client.py", line 6, in <module>
  s.connect((host,port))
ConnectionRefusedError: [Error 111] Connection refused

Connection refused tells me that [the target] is not accepting the connection.连接被拒绝告诉我 [目标] 不接受连接。 I don't think ´socket.gethostname()´ can possibly return the laptop's hostname in its current form.我认为“socket.gethostname()”不可能以当前形式返回笔记本电脑的主机名。 ´print()´ what it returns - I'd bet it's the local machine's hostname (the one creating the connection). 'print()' 它返回什么 - 我敢打赌它是本地机器的主机名(创建连接的主机名)。

Once you know where you're connecting to, Things that could go wrong:一旦你知道你要连接到哪里,可能会出错的事情:

  • Is your target listening for a connection on port 62402?您的目标是否正在侦听端口 62402 上的连接?
  • Will its firewall allow such traffic in?它的防火墙会允许此类流量进入吗?

暂无
暂无

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

相关问题 ConnectionRefusedError:[Errno 111]连接被拒绝 - ConnectionRefusedError: [Errno 111] Connection refused Ftplib ConnectionRefusedError: [Errno 111] 连接被拒绝 (python 3.5) - Ftplib ConnectionRefusedError: [Errno 111] Connection refused (python 3.5) python 套接字返回 ConnectionRefusedError: [Errno 111] 连接被拒绝 - python socket return ConnectionRefusedError: [Errno 111] Connection refused python-valve rcon minecraft&#39;ConnectionRefusedError:[Errno 111]连接被拒绝&#39; - python-valve rcon minecraft 'ConnectionRefusedError: [Errno 111] Connection refused' Python ConnectionRefusedError:[Errno 111] Docker 容器上的连接被拒绝 - Python ConnectionRefusedError: [Errno 111] Connection refused on Docker container 使用 python ftplib 下载但得到 ConnectionRefusedError: [Errno 111] Connection refused - use python ftplib downloading but get ConnectionRefusedError: [Errno 111] Connection refused ConnectionRefusedError: [Errno 111] 连接被拒绝- Mlrun - ConnectionRefusedError: [Errno 111] Connection refused- Mlrun Flask+requests API ConnectionRefusedError: [Errno 111] 连接被拒绝 - Flask+requests API ConnectionRefusedError: [Errno 111] Connection refused 在Python(多处理)中正确酸洗和取消代理对象? “ConnectionRefusedError:[Errno 111] 解压时连接被拒绝” - Properly pickling and unpickling proxy objects in Python (multiprocessing)? "ConnectionRefusedError: [Errno 111] Connection refused while unpickling" python 发送电子邮件 - ConnectionRefusedError: [Errno 111] 连接被拒绝。 请提出一些想法 - python sending email - ConnectionRefusedError: [Errno 111] Connection refused. Please suggest some ideas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM