When source_address of python socket.create_connection is used? -
socket.create_connection(address[, timeout[, source_address]])
any example show usage of source_address?
as the documentation says:
if supplied,
source_address
must 2-tuple (host
,port
) socket bind source address before connecting. if host or port ‘’ or 0 respectively os default behavior used.
in other words, it's used when need bind
socket before connecting. if don't know why you'd ever need that, don't need it. here's brief sketch of example: ftp server needs able make outgoing data connection on same interface incoming control connection. can binding same local address control connection has. so:
def make_data_conn(controlconn, port, timeout): return socket.create_connection((controlconn.getpeername()[0], port), timeout, (controlconn.getsockname()[0], 0))
Comments
Post a Comment