0

i've designed a p2p apliccation which can transfer files without a server. and everything works fine. i can transfer files between peers. but as it turns out if file size is greater than 16mb (coz the biggest file i could transfer had a size of 15810 kb) it does't transfer to peer. this is the code i'm using:

            private function browseFile(farIds:String = ""):void {
            fIds = farIds;
            file = new FileReference();
            file.addEventListener(Event.SELECT, selectHandler);
            file.browse();
        }

        private function selectHandler(event:Event):void {
            var btn = getChild("browseFile_" + fIds)
            if (btn && btn.alpha) btn.alpha = 0.5;
            file = FileReference(event.target);
            file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            file.addEventListener(Event.COMPLETE, completeHandler);
            file.load();
        }

        private function progressHandler(event:ProgressEvent):void{
            ExternalInterface.call("fileLoadProgress", event.target.name, event.bytesTotal, event.bytesLoaded)
        }

        private function completeHandler(event:Event):void{
            ExternalInterface.call("onFileLoaded")
            var fileData:Object = new Object();  
            fileData.file = event.target.data
            fileData.name = event.target.name;
            var btn = getChild("browseFile_" + fIds)
            if (btn && btn.alpha) btn.alpha = 1;
            sendSomeData(fileData, fIds, "receiveFile");
        }

        public function receiveFile(info:Object, peerID:String):void{
            ExternalInterface.call("alert", "receivedFile")
        }

        private function sendSomeData(data,farIds:String,func:String = "receiveSomeData"):void{
            for(var id:String in sendStreams){
                sendStreams[id].send(func, data, myPeerID);
            }
        }

can you tell me how can i allow transferring all files of any sizes?

thanks for your help!

RafH
  • 4,504
  • 2
  • 23
  • 23
SuperYegorius
  • 754
  • 6
  • 24

1 Answers1

1

You can split the file in chunks of say 8KB, and send them one by one. However you must check for the order of received chunks and any possible losses on the way.

Pooyan Arab
  • 136
  • 4
  • yeah, it seems the only way to solve the problem, but how can i split file and how can i join its parts? – SuperYegorius May 08 '13 at 22:55
  • 1
    You can probably use `ByteArray` to do all: converting `Object` to `ByteArray` (using `ByteArray.writeObject`), splitting into several `ByteArray`s and joining them back into one `ByteArray` (using `ByteArrat.readBytes` and `ByteArray.writeBytes`) and then decoding the result into an `Object` (using `ByteArray.readObject`). – Pooyan Arab May 08 '13 at 23:47