[Twisted-Python] Transfering a file through ActionScript xml sockets

Douglas Bagnall douglas at paradise.net.nz
Wed Nov 28 15:33:25 EST 2007

hi Raj

> I am using action script xml sockets.
> Now anyone can help me in transferring a file to client using action script xml sockets.

Why not just use HTTP? It was invented for transferring files.

Anyway, to use an XMLSocket, you'd use need to be sure your file didn't
contain zero bytes.  Then the server would use a socket class like this:

class FileSender(LineOnlyReceiver):
    delimiter = chr(0)

    def send(self, filename):
        f = open(filename)
        msg = f.read()
        self.transport.write(msg + self.delimiter)

and the Actionscript side would be something like:

   /* within the receiver class */
   this.onData = function(msg:String){
	trace("got the file contents: " + msg);

If it does contain zero bytes you need to get rid of them somehow.  The
easiest way might be to run the string through python's urllib.urlencode
on the server side, followed by actionscript's LoadVars.decode on the
client side.

But really you should use HTTP. It'll be simpler.


More information about the Twisted-Python mailing list