ConnectionRefusedError:[Errno 61]连接被拒绝

时间:2019-05-27 20:25:11

标签: python python-3.x sockets

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

ConnectionRefusedError: [Errno 61] Connection refused

我尝试将gethostname更改为127.0.0.1,但是没有用。

以下是我对Client.pyServer.py的脚本

Client.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"))

Server.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"))

0 个答案:

没有答案