def _mksocket(host, port, q, done, stop):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<EOL>s.settimeout(<NUM_LIT:2>)<EOL>attempt = <NUM_LIT:0><EOL>while not stop.is_set():<EOL><INDENT>try:<EOL><INDENT>s.connect((host, port))<EOL>return s<EOL><DEDENT>except Exception as ex:<EOL><INDENT>time.sleep(min(<NUM_LIT:30>, <NUM_LIT:2> ** attempt))<EOL>attempt += <NUM_LIT:1><EOL><DEDENT><DEDENT>
Returns a tcp socket to (host/port). Retries forever if connection fails