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

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -