Issue
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:
- ifconfig confirmed Ras-Pi ipv4 was 192.168.0.17 as expected.
- Checked if port 1234 was available on all devices. It is.
- Pinging the ras-pi from the Linux and Windows 10 devices returned 0% packet loss.
- Disabled Firewalls on all devices, just to be sure.
- Ras-Pi client.py and Linux client.py connect to Windows server.py.
- Neither Linux client.py nor Windows client.py connect to Ras-Pi server.py.
- Connecting Ras-Pi to network via wifi and then ethernet.
- "nmap -sn 192.168.0.0/24" to check if 192.168.0.17 was there and it didn't show up, even though ping works.
- Installed outstanding Ras-Pi updates, then rebooted.
- Enable SSH on Ras-Pi, then tried connecting from Linux and failed with same error (No route to host).
- Turned the router off and on again.
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.
Answered By - Michael Butscher Answer Checked By - Clifford M. (WPSolving Volunteer)