I am learning about the python socket library and am running into problems whenever I try to connect to the server running on my localhost with a client application.
Here is the server code:
import socket
HOST = '127.0.0.1' # Standard loopback interface address (localhost)
PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
print(data)
Here is the code for my client application:
import socket
HOST = "localhost" # The server's hostname or IP address
PORT = 65432 # The port used by the server
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
s.sendall(b'Hello, world')
data = s.recv(1024)
print('Received', repr(data))
Here is my error message:
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
Here is what I have tried so far:
Disabling my Window's 10 firewall completely on the windows command prompt with the use of the following command: netsh advfirewall set allprofiles state off. This did not work
To windows firewall I added an inward rule and outward rule that allows any application on my OS to access a service running on port 65432
I changed my python version from 3.8.2 to 3.7.7 because before hand I was able to run this code perfectly and I was using a python 3.7 version
I tried multiple different methods of setting the HOST variable, which include "localhost", '127.0.0.1', socket.gethost(), and socket.gethostbyname("localhost")
I am able to connect to the server through the use of the Window's telnet application but that is it. To be honest I have exhausted possible solutions that I can find online, and I know that this question has came up on this website a lot, but I have honestly tried every solution I have seen so far - which included three hours of searching.
I appreciate any possible help that you guys can give, thanks.