pythonpython-3.xnetwork-programmingraspberry-piraspbian

No route to host/WinError 10060 when connecting to Raspberry Pi


When trying to connect clients to Raspberry Pi server, Linux returns "No route to host" error, and Windows 10 returns "WinError 10060".

server.py - ran on Raspberry Pi 2 (rasbian, Bullseye, kernel 6.1.21-v7+)

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("192.168.0.17", 1234))
s.listen(5)

while True:
    clientsocket, address = s.accept()
    print(f"Connection from {address} has been established!")
    clientsocket.send(bytes("Welcome to the server!", "utf-8"))

client.py - ran on Linux and Windows 10

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.0.17", 1234))

msg = s.recv(64)
print(msg.decode("utf-8"))

I have already tried:

Non of these resulted in a solution to the Ras-Pi not being found by other devices on the network.

There were a few other things that I tried, such as adding firewall rules, but later reset to default before disabling the firewall all together.

The only thing left that I can think of to try is to completely reload the OS on the Ras-Pi, but would rather not if I can avoid it.

The thing most puzzling is that I can ping the Ras-Pi, but any other form of connection returns an error you would expect if the ip didn't exist. But it does. I hope.

I fear there's a simple solution that I've overlooked. What test have I forgotten?


Solution

  • It may be that the server uses another network adapter for the connection to the client.

    Replacing

    s.bind(("192.168.0.17", 1234))
    

    by

    s.bind(("0.0.0.0", 1234))
    

    in the server code makes the server listen on all of its adapters on port 1234.