[Twisted-Python] Transfering a file through ActionScript xml sockets
![](https://secure.gravatar.com/avatar/34a203a415f4adee47233052652ad4e1.jpg?s=120&d=mm&r=g)
Hi, I have a server-client application(by using twisted),communicating
can any one help me in transferring a file from server to client
Sorry for not giving clear information in my previous mail. I am using action script xml sockets. Now anyone can help me in transferring a file to client using action script xml sockets. Thank you in advance. Raj.. On Tue, 27 Nov 2007 10:50:35 +0530 (IST), Raj kumar <k_r_a_j_kumar@yahoo.co.in> wrote: through xml sockets. through xml sockets? At lest some references to how to use xml sockets in transferring data/files. _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python Get the freedom to save as many mails as you wish. To know how, go to http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html
![](https://secure.gravatar.com/avatar/627b464c215e4b7507bb74cefa725698.jpg?s=120&d=mm&r=g)
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() f.close() 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. Douglas
![](https://secure.gravatar.com/avatar/dd1243740a09f0676ef225404105cfc0.jpg?s=120&d=mm&r=g)
On Nov 27, 2007, at 11:50 PM, Raj kumar wrote:
Despite the name, ActionScript's XMLSockets work just fine as regular sockets. If you send XML through them, and it happens to be well- formed, it will trigger the XML-specific event handler (i think it's onXML), but you can also just use the onData handler instead. var buffer = ''; socket.onData = function(chunk){ buffer += chunk; } The data will be coming in chunks, so you'll need to buffer it in some way until you get the whole file. Obviously, Flash won't let you save this file, so I'm assuming it's some kind of datafile your app needs to parse. If that's the case, your life will be easier if you just use loadVars to retrieve a urlencoded datafile, which will be parsed and returned to you as an anonymous object. I don't have any snippets for this process, but loadVars() is a commonly used function, and there's good docs in internal Flash Help and on the adobe site. If either HTTP or custom datafiles won't work for you because of various requirements, you're pretty much going to have to write your own protocol. This is easy on the Twisted side of things, but extremely irritating on the actionscript side, IMO. How you go about this has more to do with the requirements of your current application, though... -phil
![](https://secure.gravatar.com/avatar/627b464c215e4b7507bb74cefa725698.jpg?s=120&d=mm&r=g)
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() f.close() 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. Douglas
![](https://secure.gravatar.com/avatar/dd1243740a09f0676ef225404105cfc0.jpg?s=120&d=mm&r=g)
On Nov 27, 2007, at 11:50 PM, Raj kumar wrote:
Despite the name, ActionScript's XMLSockets work just fine as regular sockets. If you send XML through them, and it happens to be well- formed, it will trigger the XML-specific event handler (i think it's onXML), but you can also just use the onData handler instead. var buffer = ''; socket.onData = function(chunk){ buffer += chunk; } The data will be coming in chunks, so you'll need to buffer it in some way until you get the whole file. Obviously, Flash won't let you save this file, so I'm assuming it's some kind of datafile your app needs to parse. If that's the case, your life will be easier if you just use loadVars to retrieve a urlencoded datafile, which will be parsed and returned to you as an anonymous object. I don't have any snippets for this process, but loadVars() is a commonly used function, and there's good docs in internal Flash Help and on the adobe site. If either HTTP or custom datafiles won't work for you because of various requirements, you're pretty much going to have to write your own protocol. This is easy on the Twisted side of things, but extremely irritating on the actionscript side, IMO. How you go about this has more to do with the requirements of your current application, though... -phil
participants (3)
-
Douglas Bagnall
-
Phil Christensen
-
Raj kumar