예제 #1
0
 def connect(self):
     
     if self.debug is True:
         print("[GUI]   : Sender        >> connexion avec le Serveur en cours ...")
     
     self.gui.log("Sender", "connexion avec le Serveur en cours ...")
     
     ip   = self.varIp.get()
     try:
         port = int(self.varPort.get())
     except:
         self.gui.log("Sender", "[ERROR] port incorrect")
         port = None
         
     if port is not None:
         self.client = Client(ip, port)
         self.client.setUi(self.gui)
     
     self.client.connexion()
예제 #2
0
class Sender():
    '''
    gere la partie envoie de commande de la GUI
    '''


    def __init__(self, GUI, win, emetteur=None, Debug=True):
        
        self.debug = Debug
        self.gui = GUI
        
        self.fenetre  = win
        self.client = emetteur
        
        self.box = Frame(self.fenetre)
        self.box.pack(side="left", expand=True, fill="both", padx=10, pady=10)
        
        self.varIp   = None
        self.varPort = None
        self.varSend = None
        
        self.initConnexion()
        self.initControler()
        self.initSender()
        
    def initConnexion(self):
        """
        parametre de la connexion
        """
        
        self.connectbox = Frame(self.box)
        self.connectbox.pack(side="top")

        self.ipLabel = Label(self.connectbox, text="Adresse IP:")
        self.ipLabel.grid(row=0, column=0, sticky=E)
        
        self.varIp = StringVar()
        self.ipBox = Entry(self.connectbox, textvariable=self.varIp, width=15)
        self.ipBox.grid(row=0, column=1)
        
        self.portLabel = Label(self.connectbox, text="Port:")
        self.portLabel.grid(row=1, column=0, sticky=E)
        
        self.varPort = StringVar()
        self.portBox = Entry(self.connectbox, textvariable=self.varPort, width=15)
        self.portBox.grid(row=1, column=1)
        
        self.buttonConnect = Button(self.connectbox, command=lambda: self.connect(), text="Connection", width=15)
        self.buttonConnect.grid(row=0, column=2, padx=10)
        
        self.buttonDisconnect = Button(self.connectbox, command=lambda: self.disconnect(), text="Deconnection", width=15)
        self.buttonDisconnect.grid(row=1, column=2, padx=10)
        
        
    def initControler(self):
        """
        Panneau de controle manuelle Translation
        """
        self.fenetrebox = Frame(self.box)
        self.fenetrebox.pack(side="top", pady=10)
        
        self.boutton_fw = Button(self.fenetrebox, command=lambda: self.cmd("fw"), text="fw", width=10)
        self.boutton_fw.grid(row=0, column=1)
        
        self.boutton_bw = Button(self.fenetrebox, command=lambda: self.cmd("bw"), text="bw", width=10)
        self.boutton_bw.grid(row=1, column=1)
        
        self.boutton_left = Button(self.fenetrebox, command=lambda: self.cmd("le"), text="left", width=10)
        self.boutton_left.grid(row=1, column=0)
        
        self.boutton_right = Button(self.fenetrebox, command=lambda: self.cmd("ri"), text="right", width=10)
        self.boutton_right.grid(row=1, column=2)
        
        """
        Panneau de controle manuelle Rotation
        """
        self.fenetreboxR = Frame(self.box)
        self.fenetreboxR.pack(side="top", pady=10)
        
        self.boutton_leftR = Button(self.fenetreboxR, command=lambda: self.cmd("rl"), text="Rot. left", width=10)
        self.boutton_leftR.grid(row=0, column=0)
        
        self.boutton_rightR = Button(self.fenetreboxR, command=lambda: self.cmd("rr"), text="Rot. right", width=10)
        self.boutton_rightR.grid(row=0, column=1)
        
        
    def initSender(self):
        """
        envoyer des commandes en manuelle
        """
        
        self.cmdbox = Frame(self.box)
        self.cmdbox.pack(side="bottom")
    
        self.varSend = StringVar()
        self.ligne_texte = Entry(self.cmdbox, textvariable=self.varSend, width=40)
        self.ligne_texte.pack(side="left")
    
        self.boutton_send = Button(self.cmdbox, command=self.cmdSend, text="send", width=10)
        self.boutton_send.pack(side="right")



    def cmd(self, cmd):
        if self.client is not None:
            if self.debug is True:
                print("[GUI]   : Sender        >> commande envoye: " + cmd)
            
            self.client.sendMsg(cmd)
                
        else:
            print(cmd)
        
    def cmdSend(self):
        self.cmd(self.varSend.get()) 
        self.varSend.initialize("")
        
    def setConnexion(self, conn):
        self.client = conn
        
        if self.debug is True:
            print("[GUI]   : Sender        >> connexion UI Emission - Thread Emetteur PRET")
            
    def connect(self):
        
        if self.debug is True:
            print("[GUI]   : Sender        >> connexion avec le Serveur en cours ...")
        
        self.gui.log("Sender", "connexion avec le Serveur en cours ...")
        
        ip   = self.varIp.get()
        try:
            port = int(self.varPort.get())
        except:
            self.gui.log("Sender", "[ERROR] port incorrect")
            port = None
            
        if port is not None:
            self.client = Client(ip, port)
            self.client.setUi(self.gui)
        
        self.client.connexion()
             
        
    def disconnect(self):
        self.client.sendMsg("END")
        
        if self.debug is True:
            print("[GUI]   : Sender        >> deconnexion du Serveur en cours")
예제 #3
0
    def run(self):
        tracker = False

        out_lck = threading.Lock()
        db = MongoConnection(out_lck)

        output(out_lck, "\nAre you a tracker?")
        output(out_lck, "1: YES")
        output(out_lck, "2: NO")

        int_choice = None
        while int_choice is None:
            try:
                option = raw_input()  # Input da tastiera
            except SyntaxError:
                option = None

            if option is None:
                output(out_lck, "Please select an option")
            else:
                try:
                    int_choice = int(option)
                except ValueError:
                    output(out_lck, "A choice is required")

        if int_choice == 1:
            output(out_lck, "YOU ARE A TRACKER")
            tracker = True
        else:
            output(out_lck, "YOU ARE A PEER!")

        # Avvio il server in ascolto sulle porte 3000 e 6000
        server = multithread_server.Server(tracker)
        server.print_trigger.connect(mainwindow.print_on_main_panel)
        server.start()

        if not tracker:
            client = Client(config.my_ipv4, config.my_ipv6,
                            int(config.my_port), config.track_ipv4,
                            config.track_ipv6, config.track_port, db, out_lck,
                            self.print_trigger, self.download_trigger,
                            self.download_progress_trigger)

            while client.session_id is None:
                # print_menu_top(out_lck)
                output(
                    out_lck,
                    "\nSelect one of the following options ('e' to exit): ")
                output(out_lck,
                       "1: Log in                                          ")
                output(out_lck,
                       "2: Set parallel downloads                          ")
                output(out_lck,
                       "3: Set part length                                 ")

                int_option = None
                try:
                    option = raw_input()
                except SyntaxError:
                    option = None

                if option is None:
                    output(out_lck, "Please select an option")
                elif option == 'e':
                    output(out_lck, "Bye bye")
                    server.stop()
                    sys.exit()  # Interrompo l'esecuzione
                else:
                    try:
                        int_option = int(option)
                    except ValueError:
                        output(out_lck, "A number is required")
                    else:
                        if int_option == 1:

                            client.login()

                            while client.session_id is not None:
                                output(
                                    out_lck,
                                    "\nSelect one of the following options ('e' to exit): "
                                )
                                output(
                                    out_lck,
                                    "1: Add file                                        "
                                )
                                output(
                                    out_lck,
                                    "2: Search file                                     "
                                )
                                output(
                                    out_lck,
                                    "3: Log out                                         "
                                )

                                int_option = None
                                try:
                                    option = raw_input()
                                except SyntaxError:
                                    option = None

                                if option is None:
                                    output(out_lck, "Please select an option")
                                else:
                                    try:
                                        int_option = int(option)
                                    except ValueError:
                                        output(out_lck, "A number is required")
                                    else:
                                        if int_option == 1:
                                            # scelgo un file dalla cartella e lo aggiungo al tracker
                                            client.share()
                                        elif int_option == 2:
                                            # creo una query e la invio al tracker
                                            client.look()
                                        elif int_option == 3:
                                            client.logout()
                                            #output(out_lck, 'Logout completed')
                                        else:
                                            output(
                                                out_lck,
                                                "Option " + str(int_option) +
                                                " not available")
                        elif int_option == 2:
                            output(
                                out_lck,
                                "Insert the number of parallel downloads: ")

                            try:
                                option = raw_input()
                            except SyntaxError:
                                option = None

                            if option is None:
                                output(out_lck, "Please insert a number")
                            else:
                                try:
                                    int_option = int(option)
                                except ValueError:
                                    output(out_lck, "A number is required")
                                else:
                                    client.parallel_downloads = int_option
                                    output(
                                        out_lck,
                                        "Parallel downloads set to: " +
                                        str(int_option))

                        elif int_option == 3:
                            output(out_lck, "Insert the new part size: ")

                            try:
                                option = raw_input()
                            except SyntaxError:
                                option = None

                            if option is None:
                                output(out_lck, "Please insert a number")
                            else:
                                try:
                                    int_option = int(option)
                                except ValueError:
                                    output(out_lck, "A number is required")
                                else:
                                    client.part_size = int_option
                                    output(
                                        out_lck, "Parts size set to: " +
                                        str(int_option))
                        else:
                            output(
                                out_lck,
                                "Option " + str(int_option) + " not available")
import sys
from Client.Client import Client

if len(sys.argv) < 4:
    print('Usage: test-viber.py app_id viber_id to_phone')
    exit(-1)

client = Client(sys.argv[1], "viber.key")
client.send_message('viber_service_msg', sys.argv[2], sys.argv[3],
                    'Hello from generic client')