I just finished uploading a new tutorial to gotoAndLearn() which shows you the basics of using binary sockets in ActionScript 3. In the example I connect to POP3 mail server and use raw commands to retrieve messages. These techniques can be used to connect to a whole range of different servers such as FTP, IMAP, Telnet, etc. Socket programming can get extremely complex but the basics are nothing that any interactive designer can’t handle easily. Here is the POP3 command reference that I used in the tutorial.
Enjoy the tutorial!
Lee








Yet again! AWESOME! Cheers Lee!
shew… that was a lot easier that what I thought it would be! your image would frighten anyone!
pretty cool to see that in action. who knew!
I’ve been waiting for a tutorial on sockets for the longest time! Thanks a million!
Awesome! Gotta love the power of Flash!
Man, that is awesome. Learn something new every time you post.
Wow great one Lee, we are looking for in depth-advanced tutorials on DisplayList like for example if i created 10 intances of a movie clip in for loop then how can i access each one, i successed to do that in getChildByName after giving each one a name and push it in array but i think its not the right way to do that .
Thanks a lot and keep it up.
thanks it’s awesome.. ever be willing to do a quick one on APE?
Just wondering.
Thanks Lee! This is so great.
Question. Servers like MS SQL Server can be queried to return their results as a well formed XML string. Is it possible to establish a socket connection with MS SQL Server from within Flash, query it, and load the resulting XML into an XML object in Flash?
(This seems like something a lot of folks might be interested in knowing, such that they wouldn’t require middleware, like PHP, ASP, JSP or .NET to do that diry work anymore.)
Does anyone know of a flash tutorial on how to setup a socket to SQL Server and query it for an XML result?
Hi lee how I can connect to a gmail server tank’s
AWESOME!thanks Lee
Cool stuff. Dixon is now immortalized in a Lee Brimelow flash tutorial.
— Just wondering, have you thought about adding comment capability directly to the tutorials page? I think it would be great for other people to be able to comment on it and talk back and forth. A digg style comment ranking would be nice to weed out all the trolls.
Nice one, but Socket class still suffers from lack of write progress status (Adobe bug base SDK-12277), so you cannot send larger files/byte chunks, for eg. FTP lib ;(
Senor Lee,
Just in time I’m trying to understand the power of Binary.
I love the socket in AS3. It is the vein connecting the browser and your server, it makes every browser a terminal, or a MMO game console…
This looks great!
The problem is I’ve been trying to try it with my own mail server and I get no answer after the first writeUTFBytes command. I tryed to trace all possible error events but nothing shows up in the output window. No “+OK Password required.” message.
On the other hand if I try with your server it does work.
So I’m guessing it’ll have something to do with my mail server configuration, but shouldn’t an error pop up?
Any hints?
Thanks
Great tutorial again lee!
How do you use it with a gmail / hotmail account?
Thanks!
hey i m thrilled about having you in prague during europe AIR tour.
see u there
I couldn’t take a look to the video, but checking the fla file it seems you didn’t mention the connect event, which I find to be something essential in some handshaking protocols.
Also, it seems you don’t talk about the policy files, that are a must for the upcoming player, everyone that hasn’t used them before (like me) would be grateful to see it.
A nice tutorial for those new to sockets tho.
It would by my thought that the forums are the best place to submit questions that require more than a one line answer. No?
is it possible to connect flash to server which are using udp ? how ?
@Steve McDonald
If you want to connect to the database directly via flash, how do you want to protect the login information? I would not save my passwords in the AS code or a path to a file containing such information.
Lee,
Thanks for the tutorial, I have tried several ways of accessing and sending mail using AS3 but I always get stuck with the security model in the flash player.
Just trying to read data from my mail.myserver.com a security error that I cannot load data from my mail server.
I am using a shared hosting environment. One example I tried to use in the past wanted a xmlsocket file served from port 843. I have no idea if or how I can do this on a shared host.
Does anyone have any experience of how to get around security issues in flash? I would appreciate a couple of pointers which way I should go.
Thanks and great work.
Neil
cool site , thanks
Hello Lee,
I have come here after days of Googling and not finding any solution. My questions are:
1) Gmail’s server too seems to be POP3. But it doesn’t work, I know the port it uses is 995, and the server’s URL is pop.gmail.com or pop.googlemail.com, but neither of these work out and it doesn’t even say “+OK Hello there” kind of thing.
2) I tried to make a basic FTP client. I can connect to it, apply almost all commands of FTP, but I can’t LIST things. Google didn’t help as this appears to be pretty advance. I know we have to use PASV Command before LIST but that too doesn’t work. I did alot of research and nothing really seems to be helpful.
3) By the method you adopted in your tutorial, I am able to perform all these functions (connect to pop mail, or ftp etc) but as soon as the file is out of the Flash Environment, everything ceases to function. What do we need to do to get it working everywhere. I tried uploading it etc.. a lot of stuff, but it didn’t work.
I’m sure you must be very busy, but after ‘days’ of research, I now believe you are the only guy who could respond to this. I also posted another question on FlashKit but didn’t get any response.
Hi!
Thank you! A very good contributions!
Eli.
Nice comments everyone. Has anyone has a reply?
Lee, I think you’re a star. You’re a great instructor. Many, many thanks. The only, small, small thing though is of coarse your an Adobe evangelist, so whilst you make everything look super-duper easy-peasey, some of the tutorials no longer work
I’m getting, with the simplist connection attempt – a several second delay, then a security sandbox error.
Fortunately due to a design flaw, there is a way around for the security sandbox, but that only worked with Flash Player 9. Now Flash 10 is out that security flaw has been fixed.
It is now necessary to install a security socket policy server before any connection attempt is allowed. A LOT of digging round the net will reveals very little information. There is some information on how to can get this working with Python and PHP here
However nothing is available for ColdFusion 8 (CF8), which is odd as it’s an Adobe product. Any help here for CF8 and a socket connection would be appreciated.
For further information on the old design flaws (AS3 & Flash 9 and below only) have a look here http://scan.flashsec.org/
Keep rockin’ Lee!
Many thanks again for your tutorials.
@Muhammad
Dude, the reason you can’t connect to gmail servers is because it needs to be over a secure connection, just connecting to port 995 isn’t enough. You need to use SSL (TLS). I don’t know how to do that yet myself otherwise I would post the code, but that’s the direction you need to look in
@Steve McDonald.
Have a look here:
http://www.mikechambers.com/blog/2007/05/07/actionscript-3-mysql-library/
Remember, the advantage of using middleware such as CF8 or PHP etc. is that the code never leaves the server. Passing the username and password over to the browser so it can be run in Flash leaves your database wide open.
You could use this method if the information is not private (say for displaying certain pages depending on the time of year or something).
You could have a user account with READ ONLY permissions for this. However INSERT,UPDATE and DELETE would be unwise.
HOWEVER… I can think of a way of actually doing this Flash by writing a mini server app working as middleware. This would have to run on the server itself, so unless you host your own server there is no way to get the .swf to run ON the server.
I recommend sticking with middleware PHP or CF8, hope this helps
caspianit.co.uk
@Neil
I’m also stuck on the flash security model, you can get a better idea what your problem is by enabling policy file logging, illustrated in the below url.
http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security_05.html
My server is a Rabbit RCM3800 microcontroller which I can connect to if I run my flash file as a “local-trusted” file. But when I run it “remote” or “local-with-networking” the policy security model prevents me from connecting.
I send the policy file by listening on port 843, and when I receive I write an ASCII stream to that socket which looks like:
Unfortunately I get this warning (and a subsequent error):
Warning: Timeout on xmlsocket://192.168.1.59:843 (at 3 seconds) while waiting for socket policy file.
Error: Request for resource at xmlsocket://192.168.1.59:3333 by requestor from file:///C:/xxx.swf is denied due to lack of policy file permissions.
Oops, my xml policy file was parsed out. It looks like this (but replace the square brackets with ><):
[cross-domain-policy]
[site-control permitted-cross-domain-policies="master-only"/]
[allow-access-from domain="mysite.com" to-ports="999,8080-8082"/]
[/cross-domain-policy]
I’ve been waiting for a tutorial on sockets for the longest time! Thanks a million!
I was wondering how you would create an array of sockets for let’s say a download manager. Any idea on how one would do that?
I learn something new from each summer. how much less I thank you.