'why can't I connect to server?

so I have just started learning network programming and I don't understand why does a connection between the client and the server is constantly denied.

import socket
my_socket = socket.socket()
my_socket.connect(("127.0.0.1", 8820))

that is the error I get:

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it


Solution 1:[1]

A client program connects to a server program. A server program is a program which listens to a particular port and a client program connects to that port.

Your program tries to connect to your own computer, port 8820. If there isn't a program running on your computer which is listening to port 8820, there is nothing to connect to so you get a connection refused error.

"Connection refused" specifically means that your computer was able to access IP address 127.0.0.1, but at that IP address, there was no program listening to port 8820.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 user253751