If I have a UDP socket like so:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
and the socket can send data:
sock.sendto("message", address)
How do I find out the port of the socket - the port used when sending data to address?
EDIT: I tried sock.getsockname() but this raises an error: [Errno 10022] An invalid argument was supplied