Python - set source port number with sockets
You need to bind
the socket to the specific port you want to send from. The bind
method takes an address tuple, much like connect
, though you can use the wildcard address. For example:
s.bind(('0.0.0.0', 1444))
Use s.bind(('', port))
.