Beispiel #1
0
    def handle(self):
        data = self.request[0]
        inData = self.request[0].strip()
        cSocket = self.request[1]
        curThread = threading.current_thread()
        result, msg = interpreter.interpret(data)

        if result == SERVER_REQUEST:
            print "{} on {} wrote:".format(self.client_address[0], curThread.name)
            print "\nServer request received - sending response...\n"
            responseData = messages.getMessage(SERVER_REQUEST_ACKNOWLEDGE, ["-i", str(TYPE_RASPMEDIA_PLAYER), "-i", "0","-s", str(configtool.readConfig()['player_name'])])
            addr = (self.client_address[0], UDP_PORT)
            #print "Response delay..."
            #time.sleep(1)
            print "Sending response to:"
            print (addr)
            if cSocket.sendto(responseData, addr):
                print "Response sent!"
            else:
                print "Sending response failed!"
        elif result == FILELIST_REQUEST:
            files = mediaplayer.getMediaFileList()
            print files
            args = ['-i', str(len(files))]
            for file in files:
                args.append('-s')
                args.append(file)
            responseData = messages.getMessage(FILELIST_RESPONSE,args)
            if cSocket.sendto(responseData, (self.client_address[0], UDP_PORT)):
                print "Filelist sent!"
        elif result == CONFIG_REQUEST:
            responseData = messages.getConfigMessage()
            if cSocket.sendto(responseData, (self.client_address[0], UDP_PORT)):
                print "Config sent!"
        elif result == PLAYER_UPDATE_ERROR:
            responseData = messages.getMessage(PLAYER_UPDATE_ERROR, ["-s", str(msg)])
            cSocket.sendto(responseData, (self.client_address[0], UDP_PORT))
Beispiel #2
0
    def handle(self):
        data = self.request[0]
        inData = self.request[0].strip()
        cSocket = self.request[1]
        curThread = threading.current_thread()
        if not self.client_address[0] in netutil.ip4_addresses():
            result, msg = interpreter.interpret(data, self.client_address[0])


            if result == SERVER_REQUEST:
                freeSpace = self.FreeDiskSpace()
                responseData = messages.getMessage(SERVER_REQUEST_ACKNOWLEDGE, ["-i", str(TYPE_RASPMEDIA_PLAYER), "-i", "0","-s", str(configtool.readConfig()['player_name']), "-i", str(freeSpace[0]), "-i", str(freeSpace[1])])
                addr = (self.client_address[0], UDP_PORT)
                print "Sending response to client:"
                print (addr)
                if cSocket.sendto(responseData, addr):
                    print "Response sent!"
                else:
                    print "Sending response failed!"
            elif result == FILELIST_REQUEST:
                files = mediaplayer.getMediaFileList()
                args = ['-i', str(len(files))]
                for file in files:
                    args.append('-s')
                    args.append(file)
                responseData = messages.getMessage(FILELIST_RESPONSE,args)
                if cSocket.sendto(responseData, (self.client_address[0], UDP_PORT)):
                    print "Filelist sent!"
            elif result == CONFIG_REQUEST:
                responseData = messages.getConfigMessage()
                if cSocket.sendto(responseData, (self.client_address[0], UDP_PORT)):
                    print "Config sent!"
            elif result == GROUP_CONFIG_REQUEST:
                response = messages.getGroupConfigMessage()
                if cSocket.sendto(response, (self.client_address[0], UDP_PORT)):
                    print "Group Config sent!"
            elif result == GROUP_CONFIG_ADD_ACTION:
                    configtool.addGroupAction(msg)
                    gConf = configtool.readGroupConfig()
                    response = messages.getMessage(GROUP_CONFIG_ADD_ACTION)
                    if cSocket.sendto(response, (self.client_address[0], UDP_PORT)):
                        print "Action saved confirmation sent!"
                    GroupManager.ReInitGroupManager(gConf)
            elif result == GROUP_CONFIG_ACTION_DELETE:
                    configtool.deleteGroupAction(msg)
                    gConf = configtool.readGroupConfig()
                    response = messages.getMessage(GROUP_CONFIG_ACTION_DELETE)
                    if cSocket.sendto(response, (self.client_address[0], UDP_PORT)):
                        print "Action deleted confirmation sent!"
                    GroupManager.ReInitGroupManager(gConf)
            elif result == PLAYER_UPDATE_ERROR:
                responseData = messages.getMessage(PLAYER_UPDATE_ERROR, ["-s", str(msg)])
                cSocket.sendto(responseData, (self.client_address[0], UDP_PORT))
            elif result == FILE_DATA_REQUEST:
                # send images from player over tcp to host in separate thread to not block other udp handling
                t = threading.Thread(target=self.SendImagesOverTCP, args=[self.client_address[0]])
                t.daemon = True
                t.start()
            elif result == DISK_INFO_REQUEST:
                freeSpace = self.FreeDiskSpace()
                responseData = messages.getMessage(DISK_INFO_REQUEST, ["-i", str(freeSpace[0]), "-i", str(freeSpace[1])])
                addr = (self.client_address[0], UDP_PORT)
                if cSocket.sendto(responseData, addr):
                    print "Disk Info sent!"
                else:
                    print "Sending disk info failed!"
        else:
            print "Received own broadcast... ignored."