def _connect(self):
self.logger.info("<STR_LIT>", self.server[<NUM_LIT:0>], self.server[<NUM_LIT:1>])<EOL>try:<EOL><INDENT>self._open_socket()<EOL>peer = self.sock.getpeername()<EOL>self.logger.info("<STR_LIT>", str(peer))<EOL>self.sock.setblocking(<NUM_LIT:1>)<EOL>self.sock.settimeout(<NUM_LIT:5>)<EOL>self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, <NUM_LIT:1>)<EOL>banner = self.sock.recv(<NUM_LIT>)<EOL>if is_py3:<EOL><INDENT>banner = banner.decode('<STR_LIT>')<EOL><DEDENT>if banner[<NUM_LIT:0>] == "<STR_LIT:#>":<EOL><INDENT>self.logger.debug("<STR_LIT>", banner.rstrip())<EOL><DEDENT>else:<EOL><INDENT>raise ConnectionError("<STR_LIT>")<EOL><DEDENT><DEDENT>except ConnectionError as e:<EOL><INDENT>self.logger.error(str(e))<EOL>self.close()<EOL>raise<EOL><DEDENT>except (socket.error, socket.timeout) as e:<EOL><INDENT>self.close()<EOL>self.logger.error("<STR_LIT>" % str(e))<EOL>if str(e) == "<STR_LIT>":<EOL><INDENT>raise ConnectionError("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>raise ConnectionError(e)<EOL><DEDENT><DEDENT>self._connected = True<EOL>
Attemps connection to the server