I'm asking this type of question although people already asked for its answers but I couldn't fix my problem still.
I've made a python code (from a learning course about networking) that goes like this :
import socket
my_socket = socket.socket()
my_socket.connect(('127.0.0.1',8820))
my_socket.send('omer'.encode())
data = my_socket.recv(1024).decode()
print('The server sent:' data)
my_socket.close()
the error I'm getting is this Traceback (most recent call last): File "e:/VISUAL STUDIO CODE/the good stuff/networking learning/ex2_1.py", line 4, in <module> my_socket.connect(('127.0.0.1',8820)) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
any explanation for why it doesn't run this simple code would be great, thanks
*edit: I used both visual studio code and pycharm to run this and got the same result
CodePudding user response:
The meaning of this error is simple: it means that there is no server process on IP address 127.0.0.1 (your own computer) which is listening to port 8820.
If you want to connect to a port you must choose an IP address and port where there is a server running.
You were probably supposed to run a server program on your computer and then run this client program at the same time.