예제 #1
0
파일: server.py 프로젝트: huangbxaaa/LFTP
    def handleFileDataAvailable(self, fd, Args):
        print("lalalalalaalalalalalalalallaalalalalalala")
        fileToSend = Args[0]
        # fileToSend = open(")
        lftpSocket = Args[1]
        print(lftpSocket.__str__())

        data = fileToSend.read(800)

        print("datais:" + data)
        if data:
            vsFtpPacket = VsPacket()
            vsFtpPacket.type = VsPacket.TYPE_DATA
            vsFtpPacket.data = data
            if lftpSocket.sendToAll(vsFtpPacket.pack()) == False:
                print("Transmission error, quiting")
                sys.exit()
        else:
            ''' Send END packet'''
            vsFtpPacket = VsPacket()
            vsFtpPacket.type = VsPacket.TYPE_END
            vsFtpPacket.data = data
            if lftpSocket.sendToAll(vsFtpPacket.pack()) == False:
                print("Transmission error, quiting")
            Event.eventFdDelete(self.handleFileDataAvailable,
                                (fileToSend, lftpSocket))
            Lftp.closeSocket(lftpSocket)
예제 #2
0
파일: client.py 프로젝트: huangbxaaa/LFTP
    def send(self):  #把send拆分为preSend
        self.lftpSocket = Lftp.createSocket(UDP_IP, UDP_PORT)
        
        for desination in self.addresses:
            self.lftpSocket.addPeer(desination)
        
        ''' 发送开始包'''
        vsFtpPacket = VsPacket()
        vsFtpPacket.type = VsPacket.TYPE_BEGIN
        if (self.RType == "get"):
            vsFtpPacket.Rt = VsPacket.RT_GET
        elif (self.RType == "put"):
            vsFtpPacket.Rt = VsPacket.RT_PUT
        vsFtpPacket.data = FileSender.processFileName(self.fileName)

        if self.lftpSocket.sendToAll(vsFtpPacket.pack()) == False:
            print("Transmission error, quiting")
            sys.exit()

        if (self.RType == "get"):
            self.filehH = open(self.fileName, 'w')
            Lftp.registerReceiveHandler(self.lftpSocket, self.receiveHandler2)
            print("Started Receiver on  " + str(self.lftpSocket.socket.getsockname()))
            # self.filehH = open(self.fileName, 'w')

        elif (self.RType == "put"):
            fileToSend = open(self.fileName)
            print("Openned fileToSend DF:" + str(fileToSend.fileno()) + " name: " + str(self.fileName))
            Lftp.registerEventHandler(self.lftpSocket, fileSender.handleEvent)
            Event.eventFd(fileToSend.fileno(), self.handleFileDataAvailable, fileToSend, "FileDataAvailable")
예제 #3
0
    def testPacketTypeEnd(self):
        vsFtpPacket = VsPacket()
        vsFtpPacket.type = VsPacket.TYPE_END
        packed = vsFtpPacket.pack()

        packet2 = VsPacket().unpack(packed)
        self.assertEqual(
            vsFtpPacket.type, packet2.type, "Type were not the same," +
            self._printPackets(vsFtpPacket, packet2))
        self.assertEqual(
            vsFtpPacket.data, packet2.data, "Data was not the same " +
            self._printPackets(vsFtpPacket, packet2))
예제 #4
0
파일: client.py 프로젝트: huangbxaaa/LFTP
 def handleFileDataAvailable(self, fd, fileToSend):      
     data = fileToSend.read(800)
     if data:
         vsFtpPacket = VsPacket()
         vsFtpPacket.type = VsPacket.TYPE_DATA
         vsFtpPacket.data = data
         if self.lftpSocket.sendToAll(vsFtpPacket.pack()) == False:
             print("Transmission error, quiting")
             sys.exit()   
         self.packetcount  = self.packetcount + 1
         print("### " + str(self.packetcount))
     else:
         ''' Send END packet'''
         vsFtpPacket = VsPacket()
         vsFtpPacket.type = VsPacket.TYPE_END
         vsFtpPacket.data = data
         if self.lftpSocket.sendToAll(vsFtpPacket.pack()) == False:
             print("Transmission error, quiting")
         Event.eventFdDelete(self.handleFileDataAvailable, fileToSend)
         print("File " + self.fileName + " sent")
         Lftp.closeSocket(self.lftpSocket)
예제 #5
0
    def testPacketTypeEnd(self):
        vsFtpPacket = VsPacket()
        vsFtpPacket.type = VsPacket.TYPE_END
        packed = vsFtpPacket.pack()

        packet2 = VsPacket().unpack(packed)
        self.assertEqual(
            vsFtpPacket.type, packet2.type, "Type were not the same," + self._printPackets(vsFtpPacket, packet2)
        )
        self.assertEqual(
            vsFtpPacket.data, packet2.data, "Data was not the same " + self._printPackets(vsFtpPacket, packet2)
        )
예제 #6
0
    def testPacketTypeData(self):
        vsFtpPacket = VsPacket()
        vsFtpPacket.type = VsPacket.TYPE_DATA
        vsFtpPacket.data = "this must be a file name"
        packed = vsFtpPacket.pack()

        packet2 = VsPacket().unpack(packed)
        self.assertEqual(
            vsFtpPacket.type, packet2.type, "Type were not the same," +
            self._printPackets(vsFtpPacket, packet2))
        self.assertEqual(
            vsFtpPacket.data, packet2.data, "Data was not the same " +
            self._printPackets(vsFtpPacket, packet2))
예제 #7
0
 def handleFileDataAvailable(self, fd, fileToSend):      
     data = fileToSend.read(800)
     if data:
         vsFtpPacket = VsPacket()
         vsFtpPacket.type = VsPacket.TYPE_DATA
         vsFtpPacket.data = data
         if self.rudpSocket.sendToAll(vsFtpPacket.pack()) == False:
             print "Transmission error, quiting"
             sys.exit()   
         self.packetcount  = self.packetcount + 1
         print "### " + str(self.packetcount)
         #time.sleep(0)
     else:
         ''' Send END packet'''
         vsFtpPacket = VsPacket()
         vsFtpPacket.type = VsPacket.TYPE_END
         vsFtpPacket.data = data
         if self.rudpSocket.sendToAll(vsFtpPacket.pack()) == False:
             print "Transmission error, quiting"
         Event.eventFdDelete(self.handleFileDataAvailable, fileToSend)
         print "File " + self.fileName + " sent"
         Rudp.closeSocket(self.rudpSocket)
예제 #8
0
    def testPacketTypeData(self):
        vsFtpPacket = VsPacket()
        vsFtpPacket.type = VsPacket.TYPE_DATA
        vsFtpPacket.data = "this must be a file name"
        packed = vsFtpPacket.pack()

        packet2 = VsPacket().unpack(packed)
        self.assertEqual(
            vsFtpPacket.type, packet2.type, "Type were not the same," + self._printPackets(vsFtpPacket, packet2)
        )
        self.assertEqual(
            vsFtpPacket.data, packet2.data, "Data was not the same " + self._printPackets(vsFtpPacket, packet2)
        )
예제 #9
0
 def send(self):
     self.rudpSocket = Rudp.createSocket(UDP_IP, UDP_PORT)
     Rudp.registerEventHandler(self.rudpSocket, fileSender.handleEvent)
     
     for desination in self.addresses:
         self.rudpSocket.addPeer(desination)
     
     fileToSend = open(self.fileName)
     Event.eventFd(fileToSend.fileno(), self.handleFileDataAvailable, fileToSend, "FileDataAvailable")
     print "Openned fileToSend DF:" + str(fileToSend.fileno()) + " name: " + str(self.fileName)        
     
     ''' Send BEGIN packet'''
     vsFtpPacket = VsPacket()
     vsFtpPacket.type = VsPacket.TYPE_BEGIN
     vsFtpPacket.data = FileSender.processFileName(self.fileName)
     if self.rudpSocket.sendToAll(vsFtpPacket.pack()) == False:
         print "Transmission error, quiting"
         sys.exit()
예제 #10
0
    def send(self):
        self.rudpSocket = Rudp.createSocket(UDP_IP, UDP_PORT)
        Rudp.registerEventHandler(self.rudpSocket, fileSender.handleEvent)

        for desination in self.addresses:
            self.rudpSocket.addPeer(desination)

        fileToSend = open(self.fileName)
        Event.eventFd(fileToSend.fileno(), self.handleFileDataAvailable,
                      fileToSend, "FileDataAvailable")
        print "Openned fileToSend DF:" + str(
            fileToSend.fileno()) + " name: " + str(self.fileName)
        ''' Send BEGIN packet'''
        vsFtpPacket = VsPacket()
        vsFtpPacket.type = VsPacket.TYPE_BEGIN
        vsFtpPacket.data = FileSender.processFileName(self.fileName)
        if self.rudpSocket.sendToAll(vsFtpPacket.pack()) == False:
            print "Transmission error, quiting"
            sys.exit()