1

I am getting the following error message, when I try to execute the Client.py script using the command Python3.7 Client.py

ConnectionRefusedError: [Errno 61] Connection refused

I tried to change the gethostname with 127.0.0.1, but it did not work.

Bellow are my scripts for Client.py and 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"))
Karthik
  • 24
  • 5
Omar
  • 13
  • 6

0 Answers0