I’m writing code on Python. The essence of the code is to create a server socket on one computer and turn it on, and on the second send a request with a message to the first computer and have it written in the terminal. But he gives me an error:
Traceback (most recent call last):
File "C:UsersCTPAXPycharmProjectspythonProject1ЕГЭ.py", line 87, in <module>
sock.connect(('127.234.231.124', 55894))
ConnectionRefusedError: [WinError 10061] The connection was not established because the destination computer rejected the connection request
here is the code for the server socket itself:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('127.234.231.124', 55894))
sock.listen()
print('Connected')
while True:
conn, addr = sock.accept()
print(addr)
data = conn.recv(1024)
conn.send(data.upper())
conn.close()
and here is the code for the client socket:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('127.234.231.124', 55894))
sock.send(bytes('Hello, world', encoding = 'UTF-8'))
data = sock.recv(1024)
sock.close()
print(data)
I tried to change the operating system, change the host
Тимофей Рачков is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1