Example #1
0
    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
Example #2
0
    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
Example #3
0
 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
Example #4
0
    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
Example #5
0
    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
Example #6
0
    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