I'm trying to implement a basic connection between two machines on the same local network (client and server), with this code:
def receive():
SERVER_HOST = "0.0.0.0"
SERVER_PORT = 5001
BUFFER_SIZE = 4096
SEPARATOR = "<SEPARATOR>"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((SERVER_HOST, SERVER_PORT))
s.listen(10)
print(f"[*] Listening as {SERVER_HOST}:{SERVER_PORT}")
print("Waiting for the client to connect... ")
client_socket, address = s.accept()
print(f"[+] {address} is connected.")
received = client_socket.recv(BUFFER_SIZE).decode()
def send():
SEPARATOR = "<SEPARATOR>"
BUFFER_SIZE = 4096
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.0.28", 5001))
print("[+] Connected to ", "192.168.0.28")
From my understanding, as the server's socket is binded to 0.0.0.0 it should listen for connections from all IPs, and the client should be able to connect to this server and send messages to it.
However the client is unable to connect with the server, timing out. When turning off the firewalls on my machines it throws a "ConnectionRefusedError: [Errno 111] Connection refused"
Addtionally when running netstat -a on the server, the command shows that the computer is listening on 127.0.0.1:5001, does this mean the socket is not binding correctly to 0.0.0.0?
I've ensured that I can ping both machines with the IP addresses that I am using, and I've tried various firewall troubleshooting methods (Turning off, creating whitelist rules)
Any help would be appreciated!
127.0.0.1represents localhost, as it is the local loopback IP.0.0.0.0on the other hand is a wildcard in the server context, it will bind to all of the machine's local IPs, including the LAN IP that other machines on the same LAN can connect to.