'TimeoutError: [WinError 10060]

I made a client-server chat, but the client program displays an error:

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

I thought the problem is with the IP address, for example 192.168.1.71 or 192.168.1.2 are frequent IP addresses. But I don't know what to do with it. Tell me please, how to fix it.

My code:

Server:

import socket

new_socket = socket.socket()
host_name = socket.gethostname()
s_ip = socket.gethostbyname(host_name)

port = 8080

new_socket.bind((host_name, port))
print("Server IP", s_ip)

name = input('Server name: ')

new_socket.listen(1) 


conn, add = new_socket.accept()

print("Received connection from: ", add[0])

client = (conn.recv(1024)).decode()
print(client + ' joined...')

conn.send(name.encode())
while True:
    message = input('Me: ')
    conn.send(message.encode())
    message = conn.recv(1024)
    message = message.decode()
    print(client, ':', message)

Client:

import socket

socket_server = socket.socket()
server_host = socket.gethostname()
ip = socket.gethostbyname(server_host)
port_ = 8080

print('Your IP: ',ip)
server_host = input('Server IP: ')
name = input('Server name: ')


socket_server.connect((server_host, port_))

socket_server.send(name.encode())
server_name = socket_server.recv(1024)
server_name = server_name.decode()

print(server_name,' joined...')
while True:
    message = (socket_server.recv(1024)).decode()
    print(server_name, ":", message)
    message = input("Me: ")
    socket_server.send(message.encode())


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source