So in preparation for Global Game Jam in a couple of weeks, I started looking into multiplayer capabilities using AS3/AIR.
It was a tiring search among many different blogs, videos, sites and presentations... there were many blank stares from me at very early hours of the morning. But in efforts to keep this to the point and make it maybe a bit easier for others who are searching for information on this topic, I'll get right to my point.
I have FINALLY gotten my P2P (Peer to Peer) connection issues sorted. I initially started looking at the ServerSocket(TCP) instead of RTMFP(UDP) within AS3, but I quickly realized that a) P2P would be much easier, and b) more applicable for my needs. I wanted to get LAN connectivity going for the purpose of a game, but to get used to the whole system, I built a chat client first (which will be later implemented into the game).
For an online example you can go here.
For an AIR client, you can download this.
This works strictly on LAN only, so opening multiple clients across multiple machines on the same network should work. AS3 uses RTMFP to connect P2P. You can read all about it on your own time, but one issue you may need to look at is, if your devices/machines can connect due to some UDP and other possible firewall restrictions. The easiest way is to check this site. If the very first light at the top is green, then you should be good to go. Or if your lights look like the below screenshot, all should also be well.
I have two machines on my network, and for some reason connecting my laptop second takes a little while before the clients see each other. But they definitely do eventually connect. But if I connect the laptop first, and anything else after, then all works immediately. I do believe this problem lies with the desktop, but I cannot figure it out, and don't have much desire to just yet. So you may or may not run into problems like that, but trust that it does work providing your firewalls allow it.
There are a lot of little details that you should know when working within RTMFP, and I won't go into it in detail here as it is very well documented all over the internetz, but of course if you do need any advice/help, please feel free to leave some comments below.
I will post the source code for the client soon, as soon as I clean it up and maybe add some comments. The client uses Minimal Comps for the UI. I found this library while searching for information on P2P, and I love it. It's very much made for just quick prototyping stuff. I did alter a couple of things for text color and whatnot, but the base classes don't need to be altered. They work very well. I highly recommend it.
Here are a couple of good tutorials and sources of information on P2P in AS3. Again, any questions or comments, please feel free to leave them below.
- Lee Burrows - P2P Flash On A Local Network Part 1
- FlashRealtime - Local Flash Peer-to-Peer Communication over LAN (without Cirrus/Stratus)
- Wikipedia - RTMFP Benefits
*UPDATE*
So originally my laptop was connected to the network via wifi, and my desktop was plugged directly into the router. And connecting was very hit or miss. Sometimes connecting with the laptop first, then the desktop would be instant, and other times connecting with the desktop first, then laptop, was instant. It was very odd.
I just plugged the laptop in, so now both machines are wired, and both orders of connecting was instant. So looks like having devices connected differently seems to throw a snag into the connectivity. Let me know if you have any of your own experiences with this and let's try to figure it out together!
- Nicholas.







Steven says:
Hi Nicholas,
I am currently doing a p2p multiplayer game project, facing the problem which your example chat room had the answer…so i would like to ask is your project develop by using fully flash and actionscript 3? and how you manage the username key in by different player to display it on the list?
Thanks in advance, hope to get your reply soon.
January 15, 2013 at 1:51 AM