TCP Port Not Working
I started a runpod instance and specifed TCP port, I got something like this
Public IP: <iphere>
Internal: 22 External: 35292
Internal: 35293 External: 35293
Internal: 35294 External: 35294
I create a simple app to test out
Now curl http://127.0.0.1:35293/hello is working
but if I change local host with public ip and same port 35293 it gets connection refused
Solution:Jump to solution
The issue here is that you need to bind to
0.0.0.0
and not the default of 127.0.0.1
to access the public IP.12 Replies
@akx I was able to get it working with gunicorn
just went through it now
Also had trouble getting it to work with flask just not, even setting the host to 0.0.0.0
If you want my requirements.txt:
Commands ran:
And then just visited:
https://docs.runpod.io/pods/configuration/expose-ports
Was able to do the HTTP part for flask, but not for TCP, which made me confused, so I tried gunicorn wondering if that was maybe the issue
Expose ports | RunPod Documentation
Learn to expose your ports.
since they used something called univorn, was thinking could be
idk why, I thought that something like:
app.run(debug=True, host='0.0.0.0', port ... would work, but it didn't.)
Which is why i used gunicorn. also i switched it to an 8000 port, didn't test it with 35XXX as u did my second time around just to follow the documentation tutorial, but i dont see why that would make a difference. tbh theoretically in my head, flask and gunicorn should have both worked, but i guess just to let you know what i tried
I think.. the code i ended up running the flask server with was a:
main.py:
But i just turned off my server before i forgot to grab it. but i basically just copied from u and kept bouncing back and forth with chatgpt, which is how i got to gunicorn.
Thanks I'll try this.
I have previously used fastapi on runpod with tcp and it did worked. Don't remember if I also tried flask earlier. This time, both didn't worked.
I'll try gunicorn
Solution
The issue here is that you need to bind to
0.0.0.0
and not the default of 127.0.0.1
to access the public IP.Changing the application is not a proper solution.
Flask, FastAPI etc should all work but most of these applications bind to 127.0.0.1 by default and you specifically have to specify to bind to 0.0.0.0.
You are right. Thanks