python - ConnectionRefusedError:[Errno 61] 连接被拒绝
问题描述
当我尝试Client.py
使用命令执行脚本时,我收到以下错误消息Python3.7 Client.py
ConnectionRefusedError: [Errno 61] Connection refused
我试图改变gethostname
with 127.0.0.1
,但没有奏效。
下面是我的脚本Client.py
和Server.py
客户端.py
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((socket.gethostname(),1234))
msg = s.recv(1024)
print(msg.decode("utf-8"))
服务器.py
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((socket.gethostname(),1234))
s.listen(5)
while True:
clientsocket,address = s.accept()
print(f"Connection from {address} has been established")
clientsocket.send(bytes("Hello","utf-8"))
解决方案
推荐阅读
- java - ANLTR 4 (Java) 捕获解析器错误/预期以进行测试
- apache-kafka - 如果领导者没有死但无法在 Kafka 中接收消息会怎样?特种作战部队?
- mysql - 通过对现有行求和来添加新行
- c++ - 如何从同一个头文件中定义 2 个类,而一个类依赖于另一个?
- tcl - treectrl 中的列跨越
- cocoapods - 如何更新未托管在 GitHub 存储库中的 cocoapod 的文档
- jquery - 使用 jQuery DataTable Buttons Plugin 不显示导出按钮
- c# - 如何使用 jQuery 滑块更改 ASP.Net 中图表的数据点 y 值?
- html - 尝试以角度创建导航栏,但未显示在本地主机上
- java - 从列表中删除重复的对