def connect_socket(host, port, blocking=True):
addr = socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM)<EOL>if not addr:<EOL><INDENT>raise Exception("<STR_LIT>"<EOL>% (host, str(port)))<EOL><DEDENT>my_socket = socket.socket(addr[<NUM_LIT:0>][<NUM_LIT:0>], addr[<NUM_LIT:0>][<NUM_LIT:1>], addr[<NUM_LIT:0>][<NUM_LIT:2>])<EOL>if not blocking:<EOL><INDENT>my_socket.setblocking(<NUM_LIT:0>)<EOL><DEDENT>try:<EOL><INDENT>my_socket.connect(addr[<NUM_LIT:0>][<NUM_LIT:4>])<EOL><DEDENT>except socket.error as e:<EOL><INDENT>if e.errno != errno.EINPROGRESS:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>return my_socket<EOL>
Create a TCP connection to the server.