def sendJoinRoomRequestOIE(self, roomName):
        """
        :param roomName: The room name (or movie title.)

        Called by the client proxy  when the user
        has clicked on the watch button or the leave button,
        indicating that she/he wants to change room.

        .. warning:
            The controller sets roomName to
            c2w.main.constants.ROOM_IDS.MAIN_ROOM when the user
            wants to go back to the main room.
        """
        #on prépare le message pour l'envoie au serveur
        #print("roomname={0}".format(roomName))
        dicoRequete = {}
        dicoRequete["taille"] = self.tailleHeader + 1
        dicoRequete["Type"] = 6
        dicoRequete["seq"] = self.seq
        if roomName == ROOM_IDS.MAIN_ROOM:
            dicoRequete["Id"] = 0
        else:
            for Id, nom in self.dicoFilm.items():
                if nom == roomName:
                    dicoRequete["Id"] = int(Id)
        joindreRq = encoder(dicoRequete)
        #sendAndWait(joindreRq)
        self.transport.write(joindreRq, (self.serverAddress, self.serverPort))

        pass
示例#2
0
    def sendJoinRoomRequestOIE(self, roomName):
        """
        :param roomName: The room name (or movie title.)

        Called by the client proxy  when the user
        has clicked on the watch button or the leave button,
        indicating that she/he wants to change room.

        .. warning:
            The controller sets roomName to
            c2w.main.constants.ROOM_IDS.MAIN_ROOM when the user
            wants to go back to the main room.
        """
        #on prépare le message pour l'envoie au serveur

        dicoRequete = {}
        dicoRequete["taille"] = self.tailleHeader + 1
        dicoRequete["Type"] = 6
        dicoRequete["seq"] = self.seq
        if roomName == ROOM_IDS.MAIN_ROOM:  #if the user wants to go to the main room, the room ID is set to 0
            dicoRequete["Id"] = 0
        else:  #we have to find the room ID which corresponds to the given roomName.
            for Id, nom in self.dicoFilm.items(
            ):  # in order to do this, we can use the attibute "dicoFilm", a dictionnary with (str(roomID), roomName) as items
                if nom == roomName:
                    dicoRequete["Id"] = int(Id)
        joindreRq = encoder(dicoRequete)
        self.sendAndWait(joindreRq)

        pass
    def sendChatMessageOIE(self, message):
        """
        :param message: The text of the chat message.
        :type message: string

        Called by the client proxy  when the user has decided to send
        a chat message

        .. note::
           This is the only function handling chat messages, irrespective
           of the room where the user is.  Therefore it is up to the
           c2wChatClientProctocol or to the server to make sure that this
           message is handled properly, i.e., it is shown only by the
           client(s) who are in the same room.
        """
        #on prépare le message pour l'envoie au serveur
        dicoMessage = {}
        dicoMessage["taille"] = self.tailleHeader + len(message)
        dicoMessage["Type"] = 5
        dicoMessage["seq"] = self.seq
        dicoMessage["message"] = message
        msgchat = encoder(dicoMessage)
        self.transport.write(msgchat, (self.serverAddress, self.serverPort))
        #on applique la politique de send-and-wait
        self.sendAndWait(msgchat)
        #une fois que le serveur a acquitté, on attends la liste de film

        pass
示例#4
0
    def sendAck(self, message):  #envoyer un message d'acquittement
        """
        Takes in parameter:
        :param string message: the message received
        
        Used to send an acknolegment message when a message is received
        from a client
        """
        ack = {}
        ack["taille"] = self.tailleHeader
        ack["Type"] = 63

        numberSeq = message.get("seq")

        if (numberSeq == self.user.userSeq):

            ack["seq"] = message.get("seq")
            self.user.incrementeUserSeq()

        else:

            ack["seq"] = self.user.userSeq - 1

        send = encoder(ack)

        self.transport.write(send)

        print("E nom {0} : {1}".format(self.user.name, ack))
示例#5
0
    def sendChatMessageOIE(self, message):
        """
        :param message: The text of the chat message.
        :type message: string

        Called by the client proxy  when the user has decided to send
        a chat message

        .. note::
           This is the only function handling chat messages, irrespective
           of the room where the user is.  Therefore it is up to the
           c2wChatClientProctocol or to the server to make sure that this
           message is handled properly, i.e., it is shown only by the
           client(s) who are in the same room.
        """
        #on prépare le message pour l'envoie au serveur
        dicoMessage = {}
        dicoMessage["taille"] = self.tailleHeader + len(
            message.encode('utf-8'))
        dicoMessage["Type"] = 5
        dicoMessage["seq"] = self.seq
        dicoMessage["message"] = message
        msgchat = encoder(dicoMessage)
        self.sendAndWait(msgchat)

        pass
示例#6
0
 def sendAcknowledgeOIE(self, ackSeq): #ackSeq est la sequence contenue dans le message à acquitter
     """
     Send an aknowledgment message
     """
     ackDico={}
     ackDico["taille"]=self.tailleHeader
     ackDico["Type"]=63
     ackDico["seq"]=ackSeq
     ackDatagram=encoder(ackDico)
     print("{0} envoie un ack de sequence: {1}".format(self.user, ackSeq))
     self.transport.write(ackDatagram)
示例#7
0
    def sendMessageToClient(self):
        """
        Sends the message to the concerned client and launchs the  
        sendAndWait function
        """

        message = self.user.message[0]
        message["seq"] = self.user.serverSeq
        send = encoder(message)
        print("E nom {0} : {1}".format(self.user.name, message))
        self.transport.write(send)
        self.user.idSend = reactor.callLater(1, self.sendAndWait)
 def sendAcknowledgeOIE(
         self, ackSeq
 ):  #ackSeq est la sequence contenue dans le message à acquitter
     """
     Send an aknowledgment message
     """
     ackDico = {}
     ackDico["taille"] = self.tailleHeader
     ackDico["Type"] = 63
     ackDico["seq"] = ackSeq
     ackDatagram = encoder(ackDico)
     self.transport.write(ackDatagram,
                          (self.serverAddress, self.serverPort))
    def sendLeaveSystemRequestOIE(self):
        """
        Called by the client proxy  when the user
        has clicked on the leave button in the main room.
        """
        logoutDico = {}
        logoutDico["taille"] = self.tailleHeader
        logoutDico["Type"] = 9
        logoutDico["sequence"] = self.seq
        paquet = encoder(logoutDico)
        self.transport.write(paquet, (self.serverAddress, self.serverPort))

        pass
示例#10
0
    def sendLeaveSystemRequestOIE(self):
        """
        Called by the client proxy  when the user
        has clicked on the leave button in the main room.
        """
        logoutDico = {}
        logoutDico["taille"] = self.tailleHeader
        logoutDico["Type"] = 9
        logoutDico["seq"] = self.seq
        paquet = encoder(logoutDico)
        self.deco = self.seq
        self.sendAndWait(paquet)

        pass
示例#11
0
 def sendMessageToClient(self, user):
     """
     Takes in parameters :
     :param user user: instance of the concerned user
     
     Sends the message to the concerned client and launchs the  
     sendAndWait function
     """
     message=user.message[0]
     message["seq"]=user.serverSeq
     send=encoder(message)
     print("E nom {0} : {1}".format(user.name,message))
     self.transport.write(send, (user.host,user.port))
     user.idSend=reactor.callLater(1, self.sendAndWait, user)
 def sendLoginRequestOIE(self, userName):
     #"""
     #:param string userName: The user name that the user has typed.
     #The client proxy calls this function when the user clicks on
     #the login button.
     #"""
     moduleLogger.debug('loginRequest called with username=%s', userName)
     dico = {}
     dico["taille"] = self.tailleHeader + len(userName)
     dico["Type"] = 1
     dico["seq"] = self.seq
     dico["user"] = userName
     self.user = userName
     connexionRq = encoder(dico)
     self.transport.write(connexionRq,
                          (self.serverAddress, self.serverPort))
示例#13
0
    def sendLoginRequestOIE(self, userName):
        """
	    :param string userName: The user name that the user has typed.
		The client proxy calls this function when the user clicks on
		the login button.
		"""
        moduleLogger.debug('loginRequest called with username=%s', userName)
        dico = {}
        dico["taille"] = self.tailleHeader + len(userName.encode('utf-8'))
        dico["Type"] = 1
        dico["seq"] = self.seq
        dico["user"] = userName
        print(userName)
        self.user = userName
        connexionRq = encoder(dico)
        self.sendAndWait(connexionRq)
示例#14
0
    def sendAndWait(self):
        """            
        Sets the SendAndWait functionality : the message is sent every seconds 
        10 times
        """
        if (self.user.numberTransmission < 10):

            send = encoder(self.user.message[0])
            print("E nom {0} : {1}".format(self.user.name,
                                           self.user.message[0]))
            self.transport.write(send)
            self.user.numberTransmission += 1
            self.user.idSend = reactor.callLater(1, self.sendAndWait)

        if (self.user.numberTransmission == 10):

            self.user.idSend.cancel()
            self.deleteUser()
示例#15
0
 def sendAndWait(self, user):
     """
     Takes in parameter :
     :param user user: instance of the concerned user
         
     Sets the SendAndWait functionality : it sends the message 10 times,
     every seconds
     
     """
     if(user.numberTransmission<10):
         send=encoder(user.message[0])
         print("E nom {0} : {1}".format(user.name,user.message[0]))
         #print("E : {0}".format(user.message[0]))
         self.transport.write(send, (user.host, user.port))
         user.numberTransmission+=1
         user.idSend=reactor.callLater(1, self.sendAndWait, user)
     if(user.numberTransmission==10):
         print("salut : {0}".format(user.name))
         user.idSend.cancel()
         self.deleteUser(user)
示例#16
0
 def sendAck(self, message, user): #envoyer un message d'acquittement
     """
     Takes in parameter:
     :param string message: the message received
     :param string user: param user user: instance of the receiver user
     
     Used to send an acknolegment message when a message is received
     from a client
     """
     ack={}
     ack["taille"]=self.tailleHeader
     ack["Type"]=63
     
     numberSeq = message.get("seq")
     if (numberSeq == user.userSeq):
         ack["seq"]=message.get("seq")
         user.incrementeUserSeq()
     else:
         ack["seq"]=user.userSeq-1
     send=encoder(ack)
     print("E : {0}".format(ack))
     self.transport.write(send, (user.host, user.port))