Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python socket taking wrong port

Why is my python script behaving this way?
I give it the instruction to connect via port 7777 but instead it is going over 45604.

I am NOT using socket.bind((socket.gethostname(),port))

Instead I work either with socket.bind(("0.0.0.0",port))
or with socket.bind(("127.0.0.1",port))
so I'm working local here. Why does my computer reroute the ports?
There should be no need for that, shouldn't it? Can I somehow disable it locally?

enter image description here

like image 230
clockw0rk Avatar asked Jun 10 '26 07:06

clockw0rk


1 Answers

I am answering in the absence of any of your actual code.. So I have to make assumptions here:

1) You have server (right side in picture) listening on port 7777.

2) You are running a client on the same machine (left side of picture) that is connecting to the server.

So, the client (on the left shell) is connecting to the server (right shell window). The server is listening on 7777 and the client is connecting to the server from 45604 (client and server cannot occupy the same port on the same machine!)

Put another way, the client is "sending" to port 7777 from port 45604. Maybe that makes better sense?


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!