Multicast Explained in Flash 10.1 P2P
July 1st, 2010
Multicast is one of the features of Flash Player 10.1 and it enables you to distribute NetStreams across the peer-to-peer mesh. It can be audio, video or even pure data stream (AMF3) - the data stream can be very handy for games, it’s much better for such purpose (like sending realtime positions, directions) than using Posting as Posting is more optimized for large number of senders to send something - like chat, status change and so on.
Difference between Unicast and Multicast
Unicast
Unicast simply delivers streams from a server to n clients. For this purpose you can use Flash Media Server and TCP protocols such as RTMP/T/S/E or HTTP protocol. Unicast also costs you a lot of resources -> 1 MBps stream delivered to 1000 clients means 1 GB upstream from server - which is CPU demanding and network transit is also huge.

Application Level Multicast
Sometimes called P2P Multicast is an optimized stream distribution among peers. It’s very cost effective as the stream is distributed among peers. You can either distribute stream from a client or FMS (with the future release).

Native IP Multicast
This one is distributed over the network not using P2P connection, but using network routing capabilities. It mostly works in internal, enterprise, VPN or LAN networks - basically in closed networks, which supports that. You can combine Native IP Multicast with Application Level Multicast to deliver combined solution called Multicast Fusion. This feature need Flash Media Server (next generation version). We will cover this feature once the new FMS is available.

Developing Multicast in Flash
We are going to build two applications, one is going to be a receiver and one broadcaster.
Once you get connected to Stratus or FMS. You need to setup the NetStream - same way like NetGroup (check Simple Chat using NetGroup tutorial).
My group is called “myGroup/multicastOne” and I am streaming stream “multicast”. You can define whatever names you want.
Broadcaster app (see whole source-code Broadcaster.mxml):
private function setupStream():void{ var groupspec:GroupSpecifier = new GroupSpecifier("myGroup/multicastOne"); groupspec.serverChannelEnabled = true; groupspec.multicastEnabled = true; stream = new NetStream(nc, groupspec.groupspecWithAuthorizations()); stream.addEventListener(NetStatusEvent.NET_STATUS,netStatus); var cam:Camera = Camera.getCamera(); video.attachCamera(cam); stream.attachCamera(cam); stream.publish("multicast"); }
Receiver app (see whole source-code Receiver.mxml):
private function setupStream():void{ var groupspec:GroupSpecifier = new GroupSpecifier("myGroup/multicastOne"); groupspec.serverChannelEnabled = true; groupspec.multicastEnabled = true; stream = new NetStream(nc, groupspec.groupspecWithAuthorizations()); stream.addEventListener(NetStatusEvent.NET_STATUS,netStatus); stream.play("multicast"); video.attachNetStream(stream); }
Watch: Developing Multicast Streaming in Flash Player 10.1 (Videotutorial)
Okay, but how can I stream from Flash Media Live Encoder. For this purpose you will need to get next generation of Flash Media Server. Once it’s available - I will write a tutorial how you can use it.
Packet distribution in Multicast
Multicast in Flash is optimized to be efficient. It works the way that you don’t upstream whole stream you received - you could do that - but you rather upstream only couple chunks that fits your network possibilities. Most of the normal DSL lines have around 8mbps download and 1mbps upload or more - so are able to receive 2mbps, but distribute only 1mbps (in optimal situation), so you would need more peers for further distribution, which would combine packets together.
Multicast in Flash is a Pull/Push system. Pull ensures to deliver the data to the peers. Push optimize the mesh, reduce latency and create multiple spanning trees. If there were only Pull, the latency of the live stream on the furthest peer would be too big. Push solves that.
Pull
There are these steps:
- Once you start distributing stream you send a map of blocks to one (or all) neighbor(s)
- Neighbor waits a short time to see who can source each block
- Neighbor picks you to send some of the blocks and sends request
- Send requested blocks to neighbor
- All transmissions are partially-reliable
- Neighbor will ask someone else if requestgoes unfulfilled


Pull then works this way:

Push
- Send map of what blocks you have to one (or all) neighbor(s)
- Neighbor notices that data is flowing
- Neighbor picks candidate sources for each sequence number slice
- Neighbor sends mask describing which sequence numbers to push
- Modulo size of mask (in this example every 3rd, 5th, and 6th)
- Periodically tests other neighbors to check for lower latency
- For each sequence number slice, keeps just quickest source
- Data is pushed immediately as it arrives for requested slices
- For each slice, there is a limit to the number of push clients served
Push then works this way

Push/Pull
By combining two above, you get effective/optimized multicast distribution, which can be illustrated like this:

Conclusion
For Multicast in Flash we use NetStream class together with GroupSpecifier and NetConnection. Multicast is the most complicated thing in Flash P2P implementation and it’s very intelligent in optimizing the delivery, chunk distribution and mesh reforming. We have three types of multicast: P2P, IP and Fusion (P2P+IP). Multicast is available with Adobe Stratus and more will be available with new FMS.
Adobe TV resources:
- Watch the session about P2P from MAX 2009 explaining multicast by Matthew Kaufman (Seek to 36:28)
- Videotutorial: Developing Multicast Streaming in Flash Player 10.1
In the next tutorial I will explain how QoS and monitoring with multicast works.
Stay tuned for more!
Where to go from here
Check other tutorials regarding P2P in Flash:
- File Sharing over P2P in Flash with Object Replication
- P2P GroupSpecifier Class Explained In Details Part 1
- Multicast Explained in Flash 10.1 P2P
- Directed Routing Explained in Flash 10.1 P2P
- Simple chat with P2P NetGroup in FP 10.1
Video tutorials:
- P2P Chat with NetGroup in Flash Player 10.1
- Multicast Streaming in Flash Player 10.1 Tutorial
Facebook comments:
23 Comments »
RSS feed for comments on this post. / TrackBack URL




Excellent work and great animations. Now I want to read the next tutorial !!!
Comment by Michael Chaize — July 1, 2010 @ 10:29 am
Hi Tom,
this looks good. I have a question, are all the push/pull actions really handled by the flash player or is there something to be programed in AS? Would:
groupspec.serverChannelEnabled = true;
groupspec.multicastEnabled = true;
+ NetStream publish() / send() / play()
work out the way how to distribute blocks? or do I have to explicitly define some inteligent distribution?
Comment by Jozef Chutka — July 1, 2010 @ 10:30 am
This whole intelligence is done by Flash Player - you can only limit peers count you are sending data to and bandwidth. If you want to control all - then you need to use Object Replication feature in FP 10.1 P2P. I will be writing article about this soon.
Comment by tom — July 1, 2010 @ 10:35 am
cool, looks like making ustram clone with 10 lines of code
Comment by Jozef Chutka — July 1, 2010 @ 1:28 pm
that’s it!
looking forward to your apps - leave some links here, when done ,)
Comment by tom — July 1, 2010 @ 2:38 pm
[...] Direct Link [...]
Pingback by Multicast Explained in Flash 10.1 P2P | Lively Flash Tuts — July 1, 2010 @ 10:13 pm
Very well thought-out and well written article, Tom. Good to have such information all at one place, and the code examples are very helpful.
One remark, though: sending from one server to ‘n’ clients describes Broadcast rather than Unicast; Unicast means one server to one client.
I know that there are plenty of other examples referring to Unicast instead of Broadcast out there (even Microsoft does it). That probably is because common Broadcast scenarios usually consist of ‘n’ instances of Unicast (1:1) connections, thus leading to a 1:n distribution.
Thus, referring to “Broadcast via ‘n’ times Unicast” or something like that might be a little bit more precise.
Best regards
Constantin
Comment by Constantin Ehrenstein — July 2, 2010 @ 12:28 pm
Thanks for a tip Constantin. That’s true. Just thought it’s obvious, but rather updated the image to be more precise.
Comment by tom — July 4, 2010 @ 8:36 pm
It seems to me that Adobe is a bit confused in Evangelizing its new technologies (and upcoming Products) and even more vague about market availability of its products (Stratus?).
Q: What are the limitations of RTMFP in Flash Player 10?
A: Flash player 10 will not enable swarming, multi-cast or broadcast quality live video. It will only enable communication from the voice and video devices native to your computer (e.g. microphone and webcam) and enables application developers to send ActionScript data messages directly between Flash Players – useful in multi-player game development.
http://download.macromedia.com/pub/labs/flashplayer10/flashplayer10_rtmfp_faq_111208.pdf
Comment by Erik — July 6, 2010 @ 1:55 pm
Erik, that was before Flash Player 10.1. Flash Player 10 enabled only point-to-point P2P. Now you can do swarming, multicast and so on.
Comment by tom — July 7, 2010 @ 2:24 pm
[...] Tip, READ: Multicast Explained in Flash 10.1 P2P [...]
Pingback by P2P Multicast in new Flash Player 10.1 — FlashRealtime.com — July 7, 2010 @ 2:26 pm
[...] Replication is the most low-level P2P access available in Flash Player 10.1 (next to Multicast, Posting and Directed Routing) It basically enables you to send chunks of between peers. Object [...]
Pingback by File Sharing over P2P in Flash with Object Replication — FlashRealtime.com — July 14, 2010 @ 9:29 pm
“Okay, but how can I stream from Flash Media Live Encoder. For this purpose you will need to get next generation of Flash Media Server. Once it’s available - I will write a tutorial how you can use it.”
Can we get some roughest idea on when the next generation FMS will come around? Thanks!
Comment by Yi — July 15, 2010 @ 6:30 pm
Hi Yi, stay tuned
That’s all I can say you…
Comment by tom — July 15, 2010 @ 6:50 pm
Excelent post, very descriptive.
The only thing I want to find out if there is any possibility to broadcast external video source (not webcam) using this tech?
Comment by Akaki — July 25, 2010 @ 12:47 pm
Hi Akaki, there will be such a possibility with new Flash Media Server.
Comment by tom — July 26, 2010 @ 11:09 am
Thanks for the reply. And one more question, have you got any idea when the new FMS will be released? at least the beta testing version.
Comment by Akaki — July 26, 2010 @ 6:34 pm
Can you write me an email to tomkr [at] adobe.com, please?
Comment by tom — July 27, 2010 @ 4:22 pm
hi Tom. your Video is very nice!!! but I still got almost same problem. which was on the Adobe TV
I got 10.1 player and SDK4.1 and DEV key and server key supposed to be right..
Error: Error #2154: The NetStream Object is invalid. This may be due to a failed NetConnection.
at flash.net::NetStream/invoke()
at flash.net::NetStream/attachCamera()
at Broadcaster/setupStream()[D:\flex4_workspaces\Stratus_Demo\src\Broadcaster.mxml:67]
at Broadcaster/netStatus()[D:\flex4_workspaces\Stratus_Demo\src\Broadcaster.mxml:50]
Comment by minoru — July 28, 2010 @ 11:52 am
[...] Flash Player 10.1 with Object Replication - P2P GroupSpecifier Class Explained In Details Part 1 - Multicast Explained in Flash 10.1 P2P - Directed Routing Explained in Flash 10.1 P2P - Simple chat with P2P NetGroup in FP [...]
Pingback by Video-on-Demand over P2P in Flash Player 10.1 with Object Replication — FlashRealtime.com — July 28, 2010 @ 8:00 pm
[...] Multicast Explained in Flash Player 10.1 [...]
Pingback by 50 resources to get up to speed with the Flash Platform : Mihai Corlan — July 29, 2010 @ 3:57 pm
[...] Multicast Explained in Flash 10.1 P2P [...]
Pingback by The next big thing: Adobe Flash P2P « Flash Video Technology and Optimizations — July 30, 2010 @ 8:01 pm
[...] Some of you guys were probably wondering how to establish P2P connections in the local network (LAN) without Stratus. Yes. It’s possible. Using native IP-only multicast. Let’s build a simple chat with Posting. Adding Multicast broadcast is just a simple next step which I am sure you can accomplish by yourself with few hints from my article about Multicast [...]
Pingback by Local Flash Peer-to-Peer Communication over LAN (without Stratus) — FlashRealtime.com — August 27, 2010 @ 2:20 pm