I had a theory I wanted to test this morning : Can I transfer files from point 2 point using Central and some sort of proxy. 5 minutes of thought, 5 minutes of code, and the answer was yes. Basically I just read in a binary file, sent the binary data across the wire, wrote the binary on receive, and opened it up. Below is the echo code. NOTE: the flashcom app does nothing but accepts the connection.
Actionscript:
-
import mx.central.Application;
-
import mx.central.Shell;
-
import mx.central.Central;
-
import mx.utils.Delegate;
-
import mx.controls.Button;
-
-
class TestCFT implements Application{
-
-
private static var __minW:Number = 500;
-
private static var __minH:Number = 500;
-
private static var __FCS_PATH:String = "rtmp://localhost/filetransfer/";
-
-
private var __shell:Shell;
-
private var __mc:MovieClip;
-
private var __nc:NetConnection;
-
private var __outstream:NetStream;
-
private var __instream:NetStream;
-
-
public function TestCFT(oMc:MovieClip){
-
-
__mc = oMc;
-
Central.initApplication(__mc, this);
-
}
-
-
public function init():Void{
-
-
__nc = new NetConnection();
-
__nc.connect(TestCFT.__FCS_PATH);
-
__nc.onStatus = Delegate.create(this, onStatus);
-
-
draw();
-
}
-
-
public function draw():Void{
-
-
var depth:Number = 0;
-
var sendBtn:Button = Button(__mc.attachMovie( "Button", "send_btn", depth++ ));
-
var img:MovieClip = __mc.createEmptyMovieClip("image_mc", depth++);
-
-
sendBtn.label = "send file";
-
sendBtn.move(10, 10);
-
sendBtn.clickHandler = Delegate.create(this, sendFile);
-
img._x = 10;
-
img._y = sendBtn.y + sendBtn.height + 10;
-
}
-
-
public function renderFile(oFile:Object):Void{
-
-
var f:FileReference = new FileReference();
-
-
f.create(oFile.name);
-
f.writeBytes(oFile.bytes);
-
f.close();
-
-
__mc.image_mc.loadMovie(oFile.name);
-
}
-
-
public function sendFile():Void{
-
-
var f = new FileReference();
-
var fTransfer:Object = {};
-
-
if (f.browse()) {
-
fTransfer.name = f.name;
-
fTransfer.bytes = f.readBytes(f.size);
-
f.close();
-
}
-
-
__outstream.send("renderFile", fTransfer);
-
}
-
-
public function onStatus(oInfo:Object):Void{
-
-
if(oInfo.code == "NetConnection.Connect.Success"){
-
__outstream = new NetStream(__nc);
-
__instream = new NetStream(__nc);
-
__instream["renderFile"] = Delegate.create(this, renderFile);
-
__outstream.publish("filetransfer");
-
__instream.play("filetransfer", -1);
-
}
-
}
-
-
public function getMinimumSize(Void):Object{
-
-
return {width:__minW, height:__minH};
-
}
-
-
public function onActivate(oShell:Shell, iAppID:Number, iShellID:Number, iBaseTabIndex:Number, oInitData:Object):Void{
-
-
__shell = oShell;
-
-
init();
-
}
-
-
public function onResize(Void):Void{ }
-
public function onDeactivate(Void):Void{}
-
public function onNetworkChange(bIsConnected:Boolean):Void{}
-
public function onNoticeEvent(oEvent:Object, oData:Object, oInitData:Object):Void{}
-
public function onPaymentResult(bResult:Boolean, oTransactionID:Object):Void{}
-
public function onSelectedItem(aData:Array):Void{}
-
public function onUninstall(Void):Void{}
-
public function showPreferences(Void):Void{}
-
}

Subscribe to RSS
#1 by Byron Saltysiak - October 28th, 2004 at 08:18
Pretty sweet idea man. So when is CentralTorrent coming out
Seriously though I think you’ll have problems with large files using this method since you’re reading the entire file into memory (or trying to). Have you found any filesize limits or practical concerns?
#2 by Kenny Bunch - October 28th, 2004 at 09:27
Byron,
Yes, this technique has it’s issues, and may not be something that you would even use. I think the concept is the important piece. I just wanted to show a possibility, others will probably figure out the best way to do it.
#3 by daz - October 28th, 2004 at 13:40
v cool!
#4 by Byron Saltysiak - October 28th, 2004 at 14:26
Yeah definitely cool – I didn’t really get to finish my thought. Actually a couple questions mostly due to my lack of knowledge about Flashcomm. Doesn’t Flashcomm require a server? How does one user connect directly to another?
Also, I was thinking about traditional sockets and thinking that large files work sort of similar to streaming right… the sender fills a send buffer one block at a time and the receiver reads from the receive buffer until eventually the entire datastream is complete and the socket is closed. So the question is: Could you change this implementation to use Flashcomm’s file streaming?
#5 by Janu - November 8th, 2005 at 01:36
Great Idea.
I have question about why using central? My guest is about FileReference(). This is also available on flash 8
#6 by Denis - July 26th, 2007 at 06:15
Can we eliminate FlasComm completely here?
Denis
http://abava.blogspot.com