socket.connect(address)
- This function connects a client socket to a server socket at
address - The format of
addressdepends on the address family - In most cases,
addressneeds to be a tuple - This tuple is formatted as
(hostname, port) - A client program sets up its
socketdifferently from a server - A server socket
bindto a port andlisten - A client calls
connectinstead - This will attach the client socket to the remote address
Example of connect
>>> import socket
>>> sock = socket(AF_INET, SOCK_STREAM) # client socket
# Establishes connection with server socket
# that is listening on port 25000
>>> serv_addr = ('localhost', 25000)
>>> sock.connect(serv_addr)References
Previous
Next