I need to check a Python server and client on the pi4B. Only I can't find how to run or open port 8080 on the pi4B.
-
1What makes you think the port is blocked? Is the Python server listening on all interfaces? How did you start the Python server?– Steve RobillardFeb 25 at 21:45
-
port 8080 is not listening. So I would like to know how to activate port 8080 for listening– Loek DompelingFeb 25 at 22:16
-
not a Raspberry Pi specific question ... it is a question about a Linux computer ... it belongs at unix.stackexchange.com/questions– jsotolaFeb 25 at 23:06
-
This is not a Pi specific question but if you had supplied details you may have got an answer. Even on a more appropriate site you will need details.– MilliwaysFeb 26 at 2:38
1 Answer
Opening a port for listening is a system call, like opening a file, and like opening a file you do it in the program (server) code. There is nothing else that needs doing unless you have configured a firewall, in which case you need to allow connections through appropriately.
It sounds a bit like you are trying to run the server and client on the same machine in which case the firewall issue is essentially mute (also, you would know if you were using one as they are not enabled by default on eg., RpiOS, or linux distros generally).
There are a couple of further caveats:
- If you are running the client and server on the same system, binding to
localhost
or127.0.0.1
is fine. However, the port will not be accessible from outside. Ports exist per network interface, and those addresses represent the (non-physical) "local loopback" interface aka.lo
in tool output such asip link
(or the depreciatedifconfig
). To bind the port onwlan0
and any other physical interface you should useINADDR_ANY
/0.0.0.0
as explained in the python docs, which binds the port on all interfaces. If you did not write the server code and are just running it, or you are using a web framework where you do not need to callbind()
orlisten()
explicitly, this information may also be relevant. - If the port is not accessible, but the Pi's IP is (eg., because the port was only bound on
localhost
), the normal error is "Connection refused". As explained here (scenario #3), this is a response from the operating system on the Pi indicating nothing is listening on the port. Because of the exact wording ("refused"), people sometimes interpret this to mean the server is listening but the OS is denying the connection, and so something further must be done. That is false.
To sum up: If the server is running and you are getting "Connection refused", either it is not using the port you think it is or it is only listening on loopback and you are trying to connect remotely.