SlideShare a Scribd company logo
P2P on the local network
          getting your devices to play together




Peter Elst - Project Cocoon Multimedia - FFK11 April 6th 2011
What will we talk about?
What will we talk about?

‣   What is P2P and how does it work?
What will we talk about?

‣   What is P2P and how does it work?

‣   How can you set up P2P with Flash Player and AIR?
What will we talk about?

‣   What is P2P and how does it work?

‣   How can you set up P2P with Flash Player and AIR?

‣   What are the use cases for P2P?
What will we talk about?

‣   What is P2P and how does it work?

‣   How can you set up P2P with Flash Player and AIR?

‣   What are the use cases for P2P?

‣   Examples and technical walkthrough
What will we talk about?

‣   What is P2P and how does it work?

‣   How can you set up P2P with Flash Player and AIR?

‣   What are the use cases for P2P?

‣   Examples and technical walkthrough

‣   Questions & answers
What is P2P?
What is P2P?

‣   P2P enables direct communication between clients
What is P2P?

‣   P2P enables direct communication between clients

‣   Clients register themselves, from there on all communication
    happens directly between connected clients
What is P2P?

‣   P2P enables direct communication between clients

‣   Clients register themselves, from there on all communication
    happens directly between connected clients

‣   Huge decrease in bandwidth requirements
What is P2P?

‣   P2P enables direct communication between clients

‣   Clients register themselves, from there on all communication
    happens directly between connected clients

‣   Huge decrease in bandwidth requirements

‣   You can do P2P communication without a server (!)
Traditional network setup
Traditional network setup
Traditional network setup

‣   Centralized communication
Traditional network setup

‣   Centralized communication

‣   Single point of failure
Traditional network setup

‣   Centralized communication

‣   Single point of failure

‣   Bandwidth needs increases with
    each additional client
Traditional network setup

‣   Centralized communication

‣   Single point of failure

‣   Bandwidth needs increases with
    each additional client

‣   Not extremely scalable
P2P network setup
P2P network setup
P2P network setup

‣   Decentralized communication
P2P network setup

‣   Decentralized communication

‣   More robust network setup
P2P network setup

‣   Decentralized communication

‣   More robust network setup

‣   Additional clients makes
    network faster
P2P network setup

‣   Decentralized communication

‣   More robust network setup

‣   Additional clients makes
    network faster

‣   Easily scalable solution for
    multi-user applications
P2P concepts
P2P concepts

‣   NetGroup - P2P channel through which you communicate
P2P concepts

‣   NetGroup - P2P channel through which you communicate

‣   Peer ID - unique identifier given to each connected client
P2P concepts

‣   NetGroup - P2P channel through which you communicate

‣   Peer ID - unique identifier given to each connected client

‣   Posting - sending a message to clients in a netgroup
P2P concepts

‣   NetGroup - P2P channel through which you communicate

‣   Peer ID - unique identifier given to each connected client

‣   Posting - sending a message to clients in a netgroup

‣   Routing - sending a message to a client via neighbor peers
P2P concepts

‣   NetGroup - P2P channel through which you communicate

‣   Peer ID - unique identifier given to each connected client

‣   Posting - sending a message to clients in a netgroup

‣   Routing - sending a message to a client via neighbor peers

‣   Object replication - transferring of data using chunks
How do you set up P2P?
How do you set up P2P?

‣   Create a NetConnection instance
How do you set up P2P?

‣   Create a NetConnection instance

‣   Connect to an RTMFP server (if wanted)
How do you set up P2P?

‣   Create a NetConnection instance

‣   Connect to an RTMFP server (if wanted)

‣   Specify a GroupSpecifier and NetGroup instance
How do you set up P2P?

‣   Create a NetConnection instance

‣   Connect to an RTMFP server (if wanted)

‣   Specify a GroupSpecifier and NetGroup instance

‣   Listen for neighbor connect and disconnect events
How do you set up P2P?

‣   Create a NetConnection instance

‣   Connect to an RTMFP server (if wanted)

‣   Specify a GroupSpecifier and NetGroup instance

‣   Listen for neighbor connect and disconnect events

‣   Post message to NetGroup or route through nearest neighbor
How do you set up P2P?

‣   Create a NetConnection instance

‣   Connect to an RTMFP server (if wanted)

‣   Specify a GroupSpecifier and NetGroup instance

‣   Listen for neighbor connect and disconnect events

‣   Post message to NetGroup or route through nearest neighbor

‣   Handle file chunks for object replication
The boilerplate code 1/2
The boilerplate code 1/2
 nc = new NetConnection();
 nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
 nc.connect("rtmfp:");
The boilerplate code 1/2
   nc = new NetConnection();
   nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
   nc.connect("rtmfp:");



gSpec = new GroupSpecifier("myNetGroupID");
gSpec.postingEnabled = true;
gSpec.routingEnabled = true;
gSpec.ipMulticastMemberUpdatesEnabled = true;
gSpec.objectReplicationEnabled = true;
...
gSpec.addIPMulticastAddress("225.225.0.1:30303");
The boilerplate code 1/2
   nc = new NetConnection();
   nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
   nc.connect("rtmfp:");



gSpec = new GroupSpecifier("myNetGroupID");
gSpec.postingEnabled = true;
gSpec.routingEnabled = true;
gSpec.ipMulticastMemberUpdatesEnabled = true;
gSpec.objectReplicationEnabled = true;
...
gSpec.addIPMulticastAddress("225.225.0.1:30303");		   	



group = new NetGroup(nc, gSpec.groupspecWithAuthorizations());	
group.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
The boilerplate code 2/2
The boilerplate code 2/2
 private function onNetStatus(evt:NetStatusEvent):void {
   switch (evt.info.code) {
     case "NetConnection.Connect.Success":
       // netconnection successful
     break;
     case "NetGroup.Neighbor.Connect":
       // client joined the netgroup
     break;
     case "NetGroup.Neighbor.Disconnect":
       // client left the netgroup
     break;
     case "NetGroup.Posting.Notify":
       // message was posted to the netgroup
     break;
     ...
   }
 }
Mobile clients - AIR for Android
Mobile clients - AIR for Android
Mobile clients - AIR for Android

‣   AIR for Android allows us to run desktop AIR files and take
    advantage of additional mobile specific features such as the
    accelerometer, geolocation,...
Mobile clients - AIR for Android

‣   AIR for Android allows us to run desktop AIR files and take
    advantage of additional mobile specific features such as the
    accelerometer, geolocation,...

‣   Almost all desktop APIs are supported
Mobile clients - AIR for Android

‣   AIR for Android allows us to run desktop AIR files and take
    advantage of additional mobile specific features such as the
    accelerometer, geolocation,...

‣   Almost all desktop APIs are supported

‣   Its a lot of fun to develop for!
Mobile clients - compiling to iOS
Mobile clients - compiling to iOS
Mobile clients - compiling to iOS

‣   AIR can cross-compile to native iOS binaries
Mobile clients - compiling to iOS

‣   AIR can cross-compile to native iOS binaries

‣   Apple started allowing third party cross-compiled applications
    back into their app store
Mobile clients - compiling to iOS

‣   AIR can cross-compile to native iOS binaries

‣   Apple started allowing third party cross-compiled applications
    back into their app store

‣   Compiled binaries generally have a larger file size
Accelerometer API
Accelerometer API
if(Accelerometer.isSupported) {
  var acc:Accelerometer = new Accelerometer();
  acc.setRequestedUpdateInterval(500);
  acc.addEventListener(AccelerometerEvent.UPDATE, update);
}



private function update(evt:AccelerometerEvent):void {
  trace("x acceleration: "+evt.accelerationX);
  trace("y acceleration: "+evt.accelerationY);
  trace("z acceleration: "+evt.accelerationZ);
}
Geolocation API
Geolocation API
if(Geolocation.isSupported){
  var geo:Geolocation = new Geolocation();
  geo.setRequestedUpdateInterval(10000);
  geo.addEventListener(GeolocationEvent.UPDATE, update);
}



private function update(evt:GeolocationEvent):void {
  trace("latitude: "+evt.latitude);
  trace("longitude: "+evt.longitude);
  trace("speed: "+evt.speed);
}
Use cases - Gaming
Use cases - Gaming

‣   Sensor data can turn any device into a game controller
Use cases - Gaming

‣   Sensor data can turn any device into a game controller

‣   High scores and other game data can be synchronized and
    persisted on the mobile device
Use cases - Gaming

‣   Sensor data can turn any device into a game controller

‣   High scores and other game data can be synchronized and
    persisted on the mobile device

‣   Practically everyone carries a phone so can immediately join in
Use cases - E-Learning
Use cases - E-Learning

‣   Students are increasingly using devices for their studies
Use cases - E-Learning

‣   Students are increasingly using devices for their studies

‣   Connected class rooms with shared whiteboards and
    collaborative tasks
Use cases - E-Learning

‣   Students are increasingly using devices for their studies

‣   Connected class rooms with shared whiteboards and
    collaborative tasks

‣   Teachers can get realtime data and statistics on how their
    students perform on particular exercises
Use cases - Sensor input
Use cases - Sensor input

‣   Mobile devices can provide additional input to your computer
Use cases - Sensor input

‣   Mobile devices can provide additional input to your computer

‣   Software can take advantage of multi-touch, accelerometer,
    geolocation data and camera access
Use cases - Sensor input

‣   Mobile devices can provide additional input to your computer

‣   Software can take advantage of multi-touch, accelerometer,
    geolocation data and camera access

‣   Mobile device becomes a second screen and helps with your
    productivity
Introducing Cocoon P2P
Introducing Cocoon P2P
Introducing Cocoon P2P
        ‣   Simple open source library focussed on
            local IP multicast with Flash Player 10.1
            or later and AIR across devices
Introducing Cocoon P2P
        ‣   Simple open source library focussed on
            local IP multicast with Flash Player 10.1
            or later and AIR across devices

        ‣   Very easy to use, avoid boilerplate code
Introducing Cocoon P2P
         ‣   Simple open source library focussed on
             local IP multicast with Flash Player 10.1
             or later and AIR across devices

         ‣   Very easy to use, avoid boilerplate code

         ‣   Early support for file transfer, video
             streaming and accelerometer


       cocoon-p2p.googlecode.com
Example - device discovery
Example - device discovery

    <p2p:LocalNetworkDiscovery id="channel" clientName="FFK11 - beyond tellerrand" /
    >

    <s:List width="80%" height="200"
         horizontalCenter="0" verticalCenter="0"
	   	   dataProvider="{channel.clients}" labelField="clientName" />
Example - messaging
Example - messaging

   <p2p:LocalNetworkDiscovery id="channel"
                           clientAdded="onClientAdded(event)"
                           clientRemoved="onClientRemoved(event)"
                           dataReceived="onDataReceived(event)"
                           loopback="true" />




channel.sendMessageToAll("Hello everyone!");
channel.sendMessageToClient("Hello you!", peerID);
Example - photo sharing
Example - photo sharing

   <p2p:LocalNetworkDiscovery id="channel"
                           dataReceived="onDataReceived(event)"
                           fileComplete="onFileComplete(event)" />




var myFile:File = File.desktopDirectory.resolvePath("image.jpg");

channel.sendFileToAll(myFile);
channel.sendFileToClient(myFile, peerID);
Example - multiplayer game
Example - multiplayer game

•   <p2p:LocalNetworkDiscovery id="channel"
                             accelerometerInterval="1000" />



<p2p:LocalNetworkDiscovery id="channel"
                           accelerometerUpdate="onAccelerometer(event)" />




private function onAccelerometer(evt:AccelerometerEvent):void {
  trace("x acceleration: "+evt.accelerationX);
  trace("y acceleration: "+evt.accelerationY);
  trace("z acceleration: "+evt.accelerationZ);
}
Example - video streaming
Example - video streaming

•   <p2p:LocalNetworkDiscovery id="channel"
                             videoStream="{cam}" />




var cam:Camera = Camera.getCamera();

var video:Video = new Video(320,240);
video.attachCamera({channel.videoStream});
Security dialog
Security dialog
Security dialog

‣   Everything covered here does not require Adobe AIR
Security dialog

‣   Everything covered here does not require Adobe AIR

‣   Using P2P in Flash Player will prompt a security dialog
Security dialog

‣   Everything covered here does not require Adobe AIR

‣   Using P2P in Flash Player will prompt a security dialog

‣   User can control whether or not
    to allow peer assisted networking
Security dialog

‣   Everything covered here does not require Adobe AIR

‣   Using P2P in Flash Player will prompt a security dialog

‣   User can control whether or not
    to allow peer assisted networking

‣   For AIR applications this is allowed
    by default without user interaction
Summary
Summary

‣   P2P is available from Flash Player 10.1 onwards and in Adobe
    AIR across devices (including iOS, BlackBerry PlayBook,
    Google TV,...)
Summary

‣   P2P is available from Flash Player 10.1 onwards and in Adobe
    AIR across devices (including iOS, BlackBerry PlayBook,
    Google TV,...)

‣   You can use this feature for connecting local devices without
    the need for a Flash Media Server
Summary

‣   P2P is available from Flash Player 10.1 onwards and in Adobe
    AIR across devices (including iOS, BlackBerry PlayBook,
    Google TV,...)

‣   You can use this feature for connecting local devices without
    the need for a Flash Media Server

‣   Devices need to be on the same wifi network and IP multicast
    must not be blocked on the router
Resources
Resources

‣   Tom Krcha - flashrealtime.com
Resources

‣   Tom Krcha - flashrealtime.com

‣   HydraP2P - github.com/devboy/HydraP2P
Resources

‣   Tom Krcha - flashrealtime.com

‣   HydraP2P - github.com/devboy/HydraP2P

‣   Cirrus (formerly Stratus) - labs.adobe.com/technologies/cirrus
Questions?
Questions?




Peter Elst

e-mail    info@peterelst.com
twitter    @peterelst
blog      www.peterelst.com
company   www.project-cocoon.com
Thank you!




Peter Elst

e-mail    info@peterelst.com
twitter    @peterelst
blog      www.peterelst.com
company   www.project-cocoon.com

More Related Content

PDF
Polyglot, Fault Tolerant Event-Driven Programming with Kafka, Kubernetes and ...
PDF
Edge architecture ieee international conference on cloud engineering
PDF
SpringOne 2016 in a nutshell
PDF
The state of curl 2020
PPTX
Scaling Push Messaging for Millions of Netflix Devices
PDF
"Enabling Googley microservices with gRPC" Riga DevDays 2018 edition
PDF
Landing code in curl
PDF
CDN_Netflix_analysis
Polyglot, Fault Tolerant Event-Driven Programming with Kafka, Kubernetes and ...
Edge architecture ieee international conference on cloud engineering
SpringOne 2016 in a nutshell
The state of curl 2020
Scaling Push Messaging for Millions of Netflix Devices
"Enabling Googley microservices with gRPC" Riga DevDays 2018 edition
Landing code in curl
CDN_Netflix_analysis

What's hot (18)

PPTX
Rethinking Cloud Proxies
PPTX
What's New in HTTP/2
PDF
Altitude San Francisco 2018: HTTP/2 Tales: Discovery and Woe
PDF
Altitude San Francisco 2018: HTTP Invalidation Workshop
PDF
Exactly Once Delivery with Kafka - JOTB2020 Mini Session
PDF
WebRTC Reborn - Cloud Expo / WebRTC Summit
PDF
Altitude San Francisco 2018: We Own Our Destiny
PDF
Astricon 2016 - Scaling ARI and Production
PDF
B 2 line game cloud - our personal ec2
PDF
Altitude SF 2017: Logging at the edge
PPTX
Meetups - The Oracle Ace Way
PPTX
KazooCon 2014 - Kazoo Scalability
PDF
Open sourcing a successful internal project - Reversim 2021
PDF
No REST - Architecting Real-time Bulk Async APIs
PDF
Broadband India Forum Session on IPv6: The Post-IPocalypse Internet
PDF
Killer Docker Workflows for Development
PPTX
Programming for the Internet of Things
PDF
Using PHP Functions! (Not those functions, Google Cloud Functions)
Rethinking Cloud Proxies
What's New in HTTP/2
Altitude San Francisco 2018: HTTP/2 Tales: Discovery and Woe
Altitude San Francisco 2018: HTTP Invalidation Workshop
Exactly Once Delivery with Kafka - JOTB2020 Mini Session
WebRTC Reborn - Cloud Expo / WebRTC Summit
Altitude San Francisco 2018: We Own Our Destiny
Astricon 2016 - Scaling ARI and Production
B 2 line game cloud - our personal ec2
Altitude SF 2017: Logging at the edge
Meetups - The Oracle Ace Way
KazooCon 2014 - Kazoo Scalability
Open sourcing a successful internal project - Reversim 2021
No REST - Architecting Real-time Bulk Async APIs
Broadband India Forum Session on IPv6: The Post-IPocalypse Internet
Killer Docker Workflows for Development
Programming for the Internet of Things
Using PHP Functions! (Not those functions, Google Cloud Functions)
Ad

Viewers also liked (20)

PPTX
Peer To Peer Networking
PDF
Peer-to-Peer Systems
PPT
My Final Project
PPTX
Android Application Development of NFC Peer-to-Peer Mode
KEY
FYP: Peer-to-Peer Communications Framework on Android Platform
PPTX
Mobile ad hoc networking: imperatives and challenges
PPTX
Ubiquiti Networks
PPTX
Manet - The Art of Networking without a Network
PPT
Communications
PDF
PDF
Synopsis on android application
PPTX
Android Synopsis
DOCX
Social Networking Site in JAVA
PPT
Wifi direct p2p app
PDF
Android internals 10 - Debugging/Profiling, Bluetooth/WiFI/RIL (rev_1.1)
PDF
WebRTC + Socket.io: building a skype-like video chat with native javascript
DOCX
Social Networking Project (website) full documentation
PPTX
Ad-Hoc Networks
PPTX
Mobile Ad hoc Networks
PDF
Agile Project Management - An introduction to Agile and the new PMI-ACP
Peer To Peer Networking
Peer-to-Peer Systems
My Final Project
Android Application Development of NFC Peer-to-Peer Mode
FYP: Peer-to-Peer Communications Framework on Android Platform
Mobile ad hoc networking: imperatives and challenges
Ubiquiti Networks
Manet - The Art of Networking without a Network
Communications
Synopsis on android application
Android Synopsis
Social Networking Site in JAVA
Wifi direct p2p app
Android internals 10 - Debugging/Profiling, Bluetooth/WiFI/RIL (rev_1.1)
WebRTC + Socket.io: building a skype-like video chat with native javascript
Social Networking Project (website) full documentation
Ad-Hoc Networks
Mobile Ad hoc Networks
Agile Project Management - An introduction to Agile and the new PMI-ACP
Ad

Similar to P2P on the local network (20)

PDF
P2P for mobile devices
PDF
Tom Krcha - Future of Flash
PPTX
P2P with Flash Player 10.1
PPTX
Flash Camp Chennai - P2P with Flash Player 10.1
PDF
Hubiquitus: An introduction
PPTX
Overview usage of ProudNet
PDF
3 f6 9_distributed_systems
PPT
Serverless (Distributed computing)
PDF
NETWOKING Power point presentation .pdf
PDF
Jornada Formativa Qualcomm y Movilforum: Alljoyn
PDF
Chapter2[one.]
PPT
Cloud Camp Milan 2K9 Telecom Italia: Where P2P?
PPTX
02 dev room6__tapand_go_jeffprosise_9Tap and Go: Proximity Networking in WinRT
PPT
Jaimin chp-1 - introduction - 2011 batch
PDF
PPT
Peer-to-peer Systems.ppt
PDF
OMG Data-Distribution Service (DDS) Tutorial - 2009
PPT
Introduction to Computer Networks
PPT
App layer
PPTX
Cloud Computing 1.3.pptx
P2P for mobile devices
Tom Krcha - Future of Flash
P2P with Flash Player 10.1
Flash Camp Chennai - P2P with Flash Player 10.1
Hubiquitus: An introduction
Overview usage of ProudNet
3 f6 9_distributed_systems
Serverless (Distributed computing)
NETWOKING Power point presentation .pdf
Jornada Formativa Qualcomm y Movilforum: Alljoyn
Chapter2[one.]
Cloud Camp Milan 2K9 Telecom Italia: Where P2P?
02 dev room6__tapand_go_jeffprosise_9Tap and Go: Proximity Networking in WinRT
Jaimin chp-1 - introduction - 2011 batch
Peer-to-peer Systems.ppt
OMG Data-Distribution Service (DDS) Tutorial - 2009
Introduction to Computer Networks
App layer
Cloud Computing 1.3.pptx

More from Peter Elst (17)

PPTX
Big boys and their litl toys
PPTX
Yes, you can do that with AIR 2.0
PPTX
FATC - AIR 2.0 workshop
PPTX
Developing with Adobe AIR
PDF
Introduction to AS3Signals
PDF
The Secret Life of a Flash Freelancer
PDF
Getting Creative with Adobe AIR
PDF
Introduction to SQLite in Adobe AIR
PDF
Creative Programming in ActionScript 3.0
ZIP
Introduction to SQLite in Adobe AIR 1.5
PDF
RIA meets Desktop
PDF
Object-Oriented ActionScript 3.0
PDF
The Evolution of the Flash Platform
PDF
SQLite in Adobe AIR
PDF
Introduction to SQLite in Adobe AIR
PDF
RIA meets Desktop
PPT
SkillsMatter - In-the-Brain session - What's new in ActionScript 3.0
Big boys and their litl toys
Yes, you can do that with AIR 2.0
FATC - AIR 2.0 workshop
Developing with Adobe AIR
Introduction to AS3Signals
The Secret Life of a Flash Freelancer
Getting Creative with Adobe AIR
Introduction to SQLite in Adobe AIR
Creative Programming in ActionScript 3.0
Introduction to SQLite in Adobe AIR 1.5
RIA meets Desktop
Object-Oriented ActionScript 3.0
The Evolution of the Flash Platform
SQLite in Adobe AIR
Introduction to SQLite in Adobe AIR
RIA meets Desktop
SkillsMatter - In-the-Brain session - What's new in ActionScript 3.0

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Cloud computing and distributed systems.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
Teaching material agriculture food technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Electronic commerce courselecture one. Pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation_ Review paper, used for researhc scholars
Cloud computing and distributed systems.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Unlocking AI with Model Context Protocol (MCP)
20250228 LYD VKU AI Blended-Learning.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Understanding_Digital_Forensics_Presentation.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Teaching material agriculture food technology
Building Integrated photovoltaic BIPV_UPV.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Digital-Transformation-Roadmap-for-Companies.pptx
Approach and Philosophy of On baking technology
Electronic commerce courselecture one. Pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?

P2P on the local network

  • 1. P2P on the local network getting your devices to play together Peter Elst - Project Cocoon Multimedia - FFK11 April 6th 2011
  • 2. What will we talk about?
  • 3. What will we talk about? ‣ What is P2P and how does it work?
  • 4. What will we talk about? ‣ What is P2P and how does it work? ‣ How can you set up P2P with Flash Player and AIR?
  • 5. What will we talk about? ‣ What is P2P and how does it work? ‣ How can you set up P2P with Flash Player and AIR? ‣ What are the use cases for P2P?
  • 6. What will we talk about? ‣ What is P2P and how does it work? ‣ How can you set up P2P with Flash Player and AIR? ‣ What are the use cases for P2P? ‣ Examples and technical walkthrough
  • 7. What will we talk about? ‣ What is P2P and how does it work? ‣ How can you set up P2P with Flash Player and AIR? ‣ What are the use cases for P2P? ‣ Examples and technical walkthrough ‣ Questions & answers
  • 9. What is P2P? ‣ P2P enables direct communication between clients
  • 10. What is P2P? ‣ P2P enables direct communication between clients ‣ Clients register themselves, from there on all communication happens directly between connected clients
  • 11. What is P2P? ‣ P2P enables direct communication between clients ‣ Clients register themselves, from there on all communication happens directly between connected clients ‣ Huge decrease in bandwidth requirements
  • 12. What is P2P? ‣ P2P enables direct communication between clients ‣ Clients register themselves, from there on all communication happens directly between connected clients ‣ Huge decrease in bandwidth requirements ‣ You can do P2P communication without a server (!)
  • 15. Traditional network setup ‣ Centralized communication
  • 16. Traditional network setup ‣ Centralized communication ‣ Single point of failure
  • 17. Traditional network setup ‣ Centralized communication ‣ Single point of failure ‣ Bandwidth needs increases with each additional client
  • 18. Traditional network setup ‣ Centralized communication ‣ Single point of failure ‣ Bandwidth needs increases with each additional client ‣ Not extremely scalable
  • 21. P2P network setup ‣ Decentralized communication
  • 22. P2P network setup ‣ Decentralized communication ‣ More robust network setup
  • 23. P2P network setup ‣ Decentralized communication ‣ More robust network setup ‣ Additional clients makes network faster
  • 24. P2P network setup ‣ Decentralized communication ‣ More robust network setup ‣ Additional clients makes network faster ‣ Easily scalable solution for multi-user applications
  • 26. P2P concepts ‣ NetGroup - P2P channel through which you communicate
  • 27. P2P concepts ‣ NetGroup - P2P channel through which you communicate ‣ Peer ID - unique identifier given to each connected client
  • 28. P2P concepts ‣ NetGroup - P2P channel through which you communicate ‣ Peer ID - unique identifier given to each connected client ‣ Posting - sending a message to clients in a netgroup
  • 29. P2P concepts ‣ NetGroup - P2P channel through which you communicate ‣ Peer ID - unique identifier given to each connected client ‣ Posting - sending a message to clients in a netgroup ‣ Routing - sending a message to a client via neighbor peers
  • 30. P2P concepts ‣ NetGroup - P2P channel through which you communicate ‣ Peer ID - unique identifier given to each connected client ‣ Posting - sending a message to clients in a netgroup ‣ Routing - sending a message to a client via neighbor peers ‣ Object replication - transferring of data using chunks
  • 31. How do you set up P2P?
  • 32. How do you set up P2P? ‣ Create a NetConnection instance
  • 33. How do you set up P2P? ‣ Create a NetConnection instance ‣ Connect to an RTMFP server (if wanted)
  • 34. How do you set up P2P? ‣ Create a NetConnection instance ‣ Connect to an RTMFP server (if wanted) ‣ Specify a GroupSpecifier and NetGroup instance
  • 35. How do you set up P2P? ‣ Create a NetConnection instance ‣ Connect to an RTMFP server (if wanted) ‣ Specify a GroupSpecifier and NetGroup instance ‣ Listen for neighbor connect and disconnect events
  • 36. How do you set up P2P? ‣ Create a NetConnection instance ‣ Connect to an RTMFP server (if wanted) ‣ Specify a GroupSpecifier and NetGroup instance ‣ Listen for neighbor connect and disconnect events ‣ Post message to NetGroup or route through nearest neighbor
  • 37. How do you set up P2P? ‣ Create a NetConnection instance ‣ Connect to an RTMFP server (if wanted) ‣ Specify a GroupSpecifier and NetGroup instance ‣ Listen for neighbor connect and disconnect events ‣ Post message to NetGroup or route through nearest neighbor ‣ Handle file chunks for object replication
  • 39. The boilerplate code 1/2 nc = new NetConnection(); nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); nc.connect("rtmfp:");
  • 40. The boilerplate code 1/2 nc = new NetConnection(); nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); nc.connect("rtmfp:"); gSpec = new GroupSpecifier("myNetGroupID"); gSpec.postingEnabled = true; gSpec.routingEnabled = true; gSpec.ipMulticastMemberUpdatesEnabled = true; gSpec.objectReplicationEnabled = true; ... gSpec.addIPMulticastAddress("225.225.0.1:30303");
  • 41. The boilerplate code 1/2 nc = new NetConnection(); nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); nc.connect("rtmfp:"); gSpec = new GroupSpecifier("myNetGroupID"); gSpec.postingEnabled = true; gSpec.routingEnabled = true; gSpec.ipMulticastMemberUpdatesEnabled = true; gSpec.objectReplicationEnabled = true; ... gSpec.addIPMulticastAddress("225.225.0.1:30303"); group = new NetGroup(nc, gSpec.groupspecWithAuthorizations()); group.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
  • 43. The boilerplate code 2/2 private function onNetStatus(evt:NetStatusEvent):void { switch (evt.info.code) { case "NetConnection.Connect.Success": // netconnection successful break; case "NetGroup.Neighbor.Connect": // client joined the netgroup break; case "NetGroup.Neighbor.Disconnect": // client left the netgroup break; case "NetGroup.Posting.Notify": // message was posted to the netgroup break; ... } }
  • 44. Mobile clients - AIR for Android
  • 45. Mobile clients - AIR for Android
  • 46. Mobile clients - AIR for Android ‣ AIR for Android allows us to run desktop AIR files and take advantage of additional mobile specific features such as the accelerometer, geolocation,...
  • 47. Mobile clients - AIR for Android ‣ AIR for Android allows us to run desktop AIR files and take advantage of additional mobile specific features such as the accelerometer, geolocation,... ‣ Almost all desktop APIs are supported
  • 48. Mobile clients - AIR for Android ‣ AIR for Android allows us to run desktop AIR files and take advantage of additional mobile specific features such as the accelerometer, geolocation,... ‣ Almost all desktop APIs are supported ‣ Its a lot of fun to develop for!
  • 49. Mobile clients - compiling to iOS
  • 50. Mobile clients - compiling to iOS
  • 51. Mobile clients - compiling to iOS ‣ AIR can cross-compile to native iOS binaries
  • 52. Mobile clients - compiling to iOS ‣ AIR can cross-compile to native iOS binaries ‣ Apple started allowing third party cross-compiled applications back into their app store
  • 53. Mobile clients - compiling to iOS ‣ AIR can cross-compile to native iOS binaries ‣ Apple started allowing third party cross-compiled applications back into their app store ‣ Compiled binaries generally have a larger file size
  • 55. Accelerometer API if(Accelerometer.isSupported) { var acc:Accelerometer = new Accelerometer(); acc.setRequestedUpdateInterval(500);   acc.addEventListener(AccelerometerEvent.UPDATE, update); } private function update(evt:AccelerometerEvent):void { trace("x acceleration: "+evt.accelerationX); trace("y acceleration: "+evt.accelerationY); trace("z acceleration: "+evt.accelerationZ); }
  • 57. Geolocation API if(Geolocation.isSupported){ var geo:Geolocation = new Geolocation(); geo.setRequestedUpdateInterval(10000);   geo.addEventListener(GeolocationEvent.UPDATE, update); } private function update(evt:GeolocationEvent):void { trace("latitude: "+evt.latitude); trace("longitude: "+evt.longitude); trace("speed: "+evt.speed); }
  • 58. Use cases - Gaming
  • 59. Use cases - Gaming ‣ Sensor data can turn any device into a game controller
  • 60. Use cases - Gaming ‣ Sensor data can turn any device into a game controller ‣ High scores and other game data can be synchronized and persisted on the mobile device
  • 61. Use cases - Gaming ‣ Sensor data can turn any device into a game controller ‣ High scores and other game data can be synchronized and persisted on the mobile device ‣ Practically everyone carries a phone so can immediately join in
  • 62. Use cases - E-Learning
  • 63. Use cases - E-Learning ‣ Students are increasingly using devices for their studies
  • 64. Use cases - E-Learning ‣ Students are increasingly using devices for their studies ‣ Connected class rooms with shared whiteboards and collaborative tasks
  • 65. Use cases - E-Learning ‣ Students are increasingly using devices for their studies ‣ Connected class rooms with shared whiteboards and collaborative tasks ‣ Teachers can get realtime data and statistics on how their students perform on particular exercises
  • 66. Use cases - Sensor input
  • 67. Use cases - Sensor input ‣ Mobile devices can provide additional input to your computer
  • 68. Use cases - Sensor input ‣ Mobile devices can provide additional input to your computer ‣ Software can take advantage of multi-touch, accelerometer, geolocation data and camera access
  • 69. Use cases - Sensor input ‣ Mobile devices can provide additional input to your computer ‣ Software can take advantage of multi-touch, accelerometer, geolocation data and camera access ‣ Mobile device becomes a second screen and helps with your productivity
  • 72. Introducing Cocoon P2P ‣ Simple open source library focussed on local IP multicast with Flash Player 10.1 or later and AIR across devices
  • 73. Introducing Cocoon P2P ‣ Simple open source library focussed on local IP multicast with Flash Player 10.1 or later and AIR across devices ‣ Very easy to use, avoid boilerplate code
  • 74. Introducing Cocoon P2P ‣ Simple open source library focussed on local IP multicast with Flash Player 10.1 or later and AIR across devices ‣ Very easy to use, avoid boilerplate code ‣ Early support for file transfer, video streaming and accelerometer cocoon-p2p.googlecode.com
  • 75. Example - device discovery
  • 76. Example - device discovery <p2p:LocalNetworkDiscovery id="channel" clientName="FFK11 - beyond tellerrand" / > <s:List width="80%" height="200" horizontalCenter="0" verticalCenter="0" dataProvider="{channel.clients}" labelField="clientName" />
  • 78. Example - messaging <p2p:LocalNetworkDiscovery id="channel" clientAdded="onClientAdded(event)" clientRemoved="onClientRemoved(event)" dataReceived="onDataReceived(event)" loopback="true" /> channel.sendMessageToAll("Hello everyone!"); channel.sendMessageToClient("Hello you!", peerID);
  • 79. Example - photo sharing
  • 80. Example - photo sharing <p2p:LocalNetworkDiscovery id="channel" dataReceived="onDataReceived(event)" fileComplete="onFileComplete(event)" /> var myFile:File = File.desktopDirectory.resolvePath("image.jpg"); channel.sendFileToAll(myFile); channel.sendFileToClient(myFile, peerID);
  • 82. Example - multiplayer game • <p2p:LocalNetworkDiscovery id="channel" accelerometerInterval="1000" /> <p2p:LocalNetworkDiscovery id="channel" accelerometerUpdate="onAccelerometer(event)" /> private function onAccelerometer(evt:AccelerometerEvent):void { trace("x acceleration: "+evt.accelerationX); trace("y acceleration: "+evt.accelerationY); trace("z acceleration: "+evt.accelerationZ); }
  • 83. Example - video streaming
  • 84. Example - video streaming • <p2p:LocalNetworkDiscovery id="channel" videoStream="{cam}" /> var cam:Camera = Camera.getCamera(); var video:Video = new Video(320,240); video.attachCamera({channel.videoStream});
  • 87. Security dialog ‣ Everything covered here does not require Adobe AIR
  • 88. Security dialog ‣ Everything covered here does not require Adobe AIR ‣ Using P2P in Flash Player will prompt a security dialog
  • 89. Security dialog ‣ Everything covered here does not require Adobe AIR ‣ Using P2P in Flash Player will prompt a security dialog ‣ User can control whether or not to allow peer assisted networking
  • 90. Security dialog ‣ Everything covered here does not require Adobe AIR ‣ Using P2P in Flash Player will prompt a security dialog ‣ User can control whether or not to allow peer assisted networking ‣ For AIR applications this is allowed by default without user interaction
  • 92. Summary ‣ P2P is available from Flash Player 10.1 onwards and in Adobe AIR across devices (including iOS, BlackBerry PlayBook, Google TV,...)
  • 93. Summary ‣ P2P is available from Flash Player 10.1 onwards and in Adobe AIR across devices (including iOS, BlackBerry PlayBook, Google TV,...) ‣ You can use this feature for connecting local devices without the need for a Flash Media Server
  • 94. Summary ‣ P2P is available from Flash Player 10.1 onwards and in Adobe AIR across devices (including iOS, BlackBerry PlayBook, Google TV,...) ‣ You can use this feature for connecting local devices without the need for a Flash Media Server ‣ Devices need to be on the same wifi network and IP multicast must not be blocked on the router
  • 96. Resources ‣ Tom Krcha - flashrealtime.com
  • 97. Resources ‣ Tom Krcha - flashrealtime.com ‣ HydraP2P - github.com/devboy/HydraP2P
  • 98. Resources ‣ Tom Krcha - flashrealtime.com ‣ HydraP2P - github.com/devboy/HydraP2P ‣ Cirrus (formerly Stratus) - labs.adobe.com/technologies/cirrus
  • 100. Questions? Peter Elst e-mail info@peterelst.com twitter @peterelst blog www.peterelst.com company www.project-cocoon.com
  • 101. Thank you! Peter Elst e-mail info@peterelst.com twitter @peterelst blog www.peterelst.com company www.project-cocoon.com

Editor's Notes