首页 > 解决方案 > ConnectionRefusedError:[Errno 61] 连接被拒绝

问题描述

当我尝试Client.py使用命令执行脚本时,我收到以下错误消息Python3.7 Client.py

ConnectionRefusedError: [Errno 61] Connection refused

我试图改变gethostnamewith 127.0.0.1,但没有奏效。

下面是我的脚本Client.pyServer.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"))

标签: pythonpython-3.xsockets

解决方案


推荐阅读