def Connect(self): if not cBaseInterFaceSettings.Connect(self): return False self.ShowDebug(u'Interface trying to connect...') try: if self.oWebSocket is None or self.oWebSocket.sock is None: uURL = ReplaceVars(self.aInterFaceIniSettings.uService) uURL = ReplaceVars( uURL, self.oInterFace.uInterFaceName + '/' + self.uConfigName + "CONFIG_") self.oWebSocket = self.cWebSocketClient(uURL, heartbeat_freq=2.0) self.oWebSocket.SetSettingObject(self) self.oWebSocket.connect() self.bInConnect = True self.bIsConnected = True tRet = self.ExecuteStandardAction('logon') self.bInConnect = False self.bIsConnected = True except Exception as e: self.ShowError( u'Interface not connected: Cannot open socket #2:' + self.aInterFaceIniSettings.uHost + ':' + self.aInterFaceIniSettings.uPort, e) self.bOnError = True return self.ShowDebug(u'Interface connected!')
def Connect(self): if not cBaseInterFaceSettings.Connect(self): return False self.ShowDebug(u'Interface trying to connect...') msg = None try: try: self.oSocket = self.oInterFace.cBluetoothSocket() self.oSocket.connect(self.aInterFaceIniSettings.uHost) except Exception as msg: self.oSocket.close() self.oSocket = None if self.oSocket is None: self.ShowError( u'Interface not connected: Cannot open socket:' + self.aInterFaceIniSettings.uHost + ':' + self.aInterFaceIniSettings.uPort, msg) self.bOnError = True return self.bIsConnected = True except Exception as e: self.ShowError( u'Interface not connected: Cannot open socket #2:' + self.aInterFaceIniSettings.uHost.uHost + ':' + self.aInterFaceIniSettings.uPort, e) self.bOnError = True return self.ShowDebug(u'Interface connected!')
def Connect(self): bRet = True if not cBaseInterFaceSettings.Connect(self): return False if self.aInterFaceIniSettings.uHost == '': return False try: self.oDevice.Connect( uHost=self.aInterFaceIniSettings.uHost, uPort=self.aInterFaceIniSettings.uPort, fTimeOut=self.aInterFaceIniSettings.fTimeOut) self.oInterFace.oInterFaceConfig.WriteDefinitionConfigPar( uSectionName=self.uSection, uVarName=u'OldDiscoveredIP', uVarValue=self.aInterFaceIniSettings.uHost) self.bIsConnected = True return self.bIsConnected except Exception as e: if hasattr(e, "errno"): if e.errno == 10051: self.bOnError = True self.ShowWarning(u'Cannot connect (No Network):' + self.aInterFaceIniSettings.uHost + ':' + self.aInterFaceIniSettings.uPort) return False self.ShowError( u'Cannot connect:' + self.aInterFaceIniSettings.uHost + ':' + self.aInterFaceIniSettings.uPort, e) self.bOnError = True return False
def Connect(self): if not cBaseInterFaceSettings.Connect(self): return False try: for res in socket.getaddrinfo( self.aInterFaceIniSettings.uHost, int(self.aInterFaceIniSettings.uPort), socket.AF_UNSPEC, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res try: self.oSocket = socket.socket(af, socktype, proto) self.oSocket.settimeout(2.0) except socket.error: self.oSocket = None continue try: self.oSocket.connect(sa) self.oSocket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) except socket.error: self.oSocket.close() self.oSocket = None continue break if not self.oSocket is None: if self.oThread: self.bStopThreadEvent = True self.oThread.join() self.oThread = None self.bStopThreadEvent = False self.oThread = Thread(target=self.Receive, ) self.oThread.start() if self.oSocket is None: self.ShowError(u'Cannot open socket' + self.aInterFaceIniSettings.uHost + ':' + self.aInterFaceIniSettings.uPort) self.bOnError = True return self.bIsConnected = True except Exception as e: self.ShowError( u'Cannot open socket #2' + self.aInterFaceIniSettings.uHost + ':' + self.aInterFaceIniSettings.uPort, e) self.bOnError = True return self.ShowDebug(u'Interface connected!')
def Connect(self): if not cBaseInterFaceSettings.Connect(self): return False try: for res in socket.getaddrinfo( self.aInterFaceIniSettings.uHost, int(self.aInterFaceIniSettings.uPort), socket.AF_INET, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res try: self.oSocket = socket.socket(af, socktype, proto) self.oSocket.settimeout(5.0) except socket.error: self.oSocket = None continue try: self.oSocket.connect(sa) except socket.error: self.oSocket.close() self.oSocket = None continue break if self.oSocket is None: self.ShowError(u'Cannot open socket' + self.aInterFaceIniSettings.uHost + ':' + self.aInterFaceIniSettings.uPort) self.bOnError = True return if not self.aInterFaceIniSettings.uUser == u'': self.oSocket.send(self.aInterFaceIniSettings.uUser + "\r" + self.aInterFaceIniSettings.uPassword + "\r") # Receive the prompts (will be "Login:\r\nPassword:") self.sResponse = self.oSocket.recv(2048) self.ShowDebug(u'Login Response' + self.sResponse) self.oSocket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) self.bIsConnected = True except Exception as e: self.ShowError( u'Cannot open socket #2' + self.aInterFaceIniSettings.uHost + ':' + self.aInterFaceIniSettings.uPort, e) self.bOnError = True
def Connect(self): if self.bInConnect: return True bRet = True if not cBaseInterFaceSettings.Connect(self): return False try: self.bInConnect = True self.bIsConnected = True tRet = self.ExecuteStandardAction('logon') self.bInConnect = False if type(tRet) == tuple: iStatusCode, uRes = tRet[0], tRet[1] elif type(tRet) == int: iStatusCode = tRet else: iStatusCode = 0 # self.bIsConnected = (iStatusCode == 200) self.bIsConnected = (iStatusCode == 0) if not self.bIsConnected: self.ShowDebug(u'Auth. failed:' + self.oInterFace.uResponse) self.ShowError(u'Cannot connect:' + self.aInterFaceIniSettings.uHost + ':' + self.aInterFaceIniSettings.uPort) return self.bIsConnected except Exception as e: self.ShowError( u'Cannot connect:' + self.aInterFaceIniSettings.uHost + ':' + self.aInterFaceIniSettings.uPort, e) self.bOnError = True return False
def Connect(self): if not cBaseInterFaceSettings.Connect(self): return False if self.aInterFaceIniSettings.uHost == '': return False try: if self.oDevice is None: # self.oDevice = Cube(address=self.aInterFaceIniSettings.uHost, port=ToInt(self.aInterFaceIniSettings.uPort)) self.oDevice = MaxCube( MaxCubeConnection( host=self.aInterFaceIniSettings.uHost, port=ToInt(self.aInterFaceIniSettings.uPort))) # self.oDevice.connect() self.oInterFace.oInterFaceConfig.WriteDefinitionConfigPar( uSectionName=self.uSection, uVarName=u'OldDiscoveredIP', uVarValue=self.aInterFaceIniSettings.uHost) self.bIsConnected = True return self.bIsConnected except Exception as e: if hasattr(e, "errno"): if e.errno == 10051: self.bOnError = True self.ShowWarning(u'Cannot connect (No Network):' + self.aInterFaceIniSettings.uHost + ':' + self.aInterFaceIniSettings.uPort) return False self.ShowError( u'Cannot connect:' + self.aInterFaceIniSettings.uHost + ':' + self.aInterFaceIniSettings.uPort, e) self.bOnError = True return False
def Connect(self): if not cBaseInterFaceSettings.Connect(self): return False try: aWidgetPlayer = Globals.oTheScreen.FindWidgets( uPageName=self.oAction.oParentWidget.oParentScreenPage. uPageName, uWidgetName=self.aInterFaceIniSettings.uWidgetName) if len(aWidgetPlayer) > 0: self.oWidgetPlayer = aWidgetPlayer[0] if self.oWidgetPlayer is not None: self.bIsConnected = True self.oWidgetPlayer.Connect(self) return True else: self.ShowError(u'Cannot Find Widget') self.bOnError = True return False except Exception as e: self.ShowError(u'Cannot Find Widget', e) self.bOnError = True return False
def Connect(self): if not cBaseInterFaceSettings.Connect(self): return False try: try: #due to a telnet unicode bug in python 2.7, we need to convert to string self.ShowDebug( u'Connecting to %s:%s with user: [%s] , password: [%s]' % (str(self.aInterFaceIniSettings.uHost), str(self.aInterFaceIniSettings.uPort), self.aInterFaceIniSettings.uUser, self.aInterFaceIniSettings.uPassword)) self.oTelnet = telnetlib.Telnet( str(self.aInterFaceIniSettings.uHost), str(self.aInterFaceIniSettings.uPort), self.aInterFaceIniSettings.fTimeOut) oSocket = self.oTelnet.get_socket() oSocket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2048) if not self.aInterFaceIniSettings.uTerminalType == u'': self.oTelnet.set_option_negotiation_callback( self.SetOption) if not self.aInterFaceIniSettings.uUser == u'': self.oTelnet.read_until("login: "******"\n") if not self.aInterFaceIniSettings.uPassword == u'': self.oTelnet.read_until("assword: ", 5) self.ShowDebug(u'Sending Password') self.oTelnet.write( str(self.aInterFaceIniSettings.uPassword + "\n")) except socket.gaierror as e: self.ShowError( u'Cannot open telnet session:' + self.aInterFaceIniSettings.uHost, e) self.bOnError = True return except socket.error as e: self.ShowError( u'Connection refused:' + self.aInterFaceIniSettings.uHost, e) self.bOnError = True return self.ShowDebug(u'Connected!') if self.oThread: self.bStopThreadEvent = True self.oThread.join() self.oThread = None self.bStopThreadEvent = False self.oThread = Thread(target=self.Receive, ) self.oThread.start() self.bIsConnected = True except Exception as e: self.ShowError( u'Cannot open socket #2:' + self.aInterFaceIniSettings.uHost, e) self.bOnError = True