当我尝试使用命令Client.py
执行Python3.7 Client.py
脚本时,出现以下错误消息
ConnectionRefusedError: [Errno 61] Connection refused
我尝试将gethostname
更改为127.0.0.1
,但是没有用。
以下是我对Client.py
和Server.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"))