def send(self, data, error_except=True): if not error_except: return self.tcpclient.sendall(data) try: self.tcpclient.sendall(data) except Exception as e: ALPSDebug.alps_error(e, '\n', inspect.getframeinfo((inspect.currentframe().f_back))) return False return True
def send(self, path, message, error_except=True): if not error_except: return self.unixconnection.socket.sendto(message, path) try: self.unixconnection.socket.sendto(message, path) except Exception as e: ALPSDebug.alps_error(e, '\n', ALPSDebug.format_inspect_traceback(inspect.currentframe().f_back)) return False return True
def Terminate(): import os import FrameworkSupport if FrameworkSupport.PID: import ALPSPlatform import ALPSDebug ALPSDebug.alps_print("WSDT Framework Terminated") if ALPSPlatform.os_system == ALPSPlatform.OS_WINDOWS: os.system("taskkill /T /F /PID %d" % FrameworkSupport.PID) elif ALPSPlatform.os_system == ALPSPlatform.OS_LINUX: os.system("kill -9 -%d" % FrameworkSupport.PID)
def send_to_all_connections(self, message, error_except=True): if len(self.connections) == 0: return True for sock_obj in self.connections.values(): if error_except: try: sock_obj.sendall(message) except Exception as e: ALPSDebug.alps_error(e, '\n', inspect.getframeinfo((inspect.currentframe().f_back))) return False else: sock_obj.sendall(message) return True
def connect(self, thread_name="TCPClient Thread", error_except=True): if not error_except: self.tcpclient.connect((self.ip_string, self.port)) else: try: self.tcpclient.connect((self.ip_string, self.port)) except Exception as e: ALPSDebug.alps_error(e) return False self.receiver_thread = ALPSThread(threadfunc=self.receiver_handle_thread, threadname=thread_name) self.receiver_thread.setDaemon(not self.background) self.receiver_thread.start() return True
def send(self, client_address, message, error_except=True): if client_address not in self.connections.keys(): ALPSDebug.alps_error('socket not exist error') return False connection = self.connections[client_address] if not error_except: return connection.sendall(message) try: connection.sendall(message) except Exception as e: ALPSDebug.alps_error(e, '\n', inspect.getframeinfo((inspect.currentframe().f_back))) return False return True
def send(self, client_address, message, error_except=True): if type(client_address) is tuple: addr_tuple = client_address else: addr_tuple = (client_address.split(':')[0], int(client_address.split(':')[1])) if not error_except: return self.udpconnection.socket.sendto(message, addr_tuple) try: self.udpconnection.socket.sendto(message, addr_tuple) except Exception as e: ALPSDebug.alps_error(e, '\n', inspect.getframeinfo((inspect.currentframe().f_back))) return False return True
def __connection_attempt_thread(self): def send_func(packet): self.tcp_client.send(packet) while True: time.sleep(5) try: self.tcp_client.connect("Distributor TCP Client Thread", error_except=False) break except: ALPSDebug.alps_print(ALPSDebug.LEVEL.WARN, 'Distributor TCP Client failed to connect to server(%s:%s).' % (self.tcp_client.ip_string, self.tcp_client.port), 'Try again later.') self.connection_append(self, (self.tcp_client.ip_string, self.tcp_client.port), lambda packet:self.tcp_client.send(packet) )
def __output(cls, *args): if args: ALPSDebug.alps_print(level, msg % args) else: ALPSDebug.alps_print(level, msg)