SlideShare a Scribd company logo
1 of 24
Speaker: 陳柏伸
Source code:
https://android.googlesource.com/platform/de
velopment/+/master/samples/WiFiDirectDemo
WiFi Direct
Outline
• 背景知識
• Demo WiFi Direct照片分享app
• 實作WiFi Direct照片分享app
Introduction
• Wi-Fi直連(英語:Wi-Fi Direct),之前曾
被稱為Wi-Fi 點對點(Wi-Fi Peer-to-Peer),
是一套軟體協定,讓 wifi 裝置可以不必透過
無線網路基地台(Access Point),以點對
點的方式,直接與另一個 wifi 裝置連線,進
行高速資料傳輸。這個協定由Wi-Fi聯盟發
展、支援與授與認證,通過認證的產品將
可獲得Wi-Fi 認證 Wi-Fi Direct標誌。
優點
• 點對點傳輸
• 傳輸速度快
• 安全性高
• 區域廣播功能
• 向下相容性
缺點
• 耗電
相關技術比較
• Bluetooth4.0
Enabled Wi-Fi Direct
Demo –
WiFi Direct Photo Sharing app
WifiP2pManager
• The WifiP2pManager class provides methods to allow
you to interact with the Wi-Fi hardware on your device
to do things like discover and connect to peers.
• WifiP2pManager methods:
• initialize()
• connect()
• discoverPeers()
• requestPeers()
• …
Asynchronous methods
WifiP2pManager methods let you pass in a listener, so that
the Wi-Fi P2P framework can notify your activity of the
status of a call.
不同的WifiP2pManager methods需要帶入不同的listener當參數, 像
manager.discoverPeers 就需要帶入 WifiP2pManager.ActionListListener.
Wifip2p events are intents
• WIFI_P2P_CONNECTION_CHANGED_ACTION
• WIFI_P2P_PEERS_CHANGED_ACTION
• WIFI_P2P_STATE_CHANGED_ACTION
• WIFI_P2P_THIS_DEVICE_CHANGED_ACTION
The Wi-Fi P2P APIs define intents that are broadcast when certain
Wi-Fi P2P events happen, such as when a new peer is discovered
or when a device's Wi-Fi state changes. You can register to
receive these intents in your application by creating a broadcast
receiver that handles these intents.
Broadcast Receiver for Wi-Fi P2P
Intents
A broadcast receiver allows you to receive intents
broadcast by the Android system, so that your application
can respond to events that you are interested in.
Workflow - Broadcast Receiver
discoverPeers()
discoverPeers() & ActionListener
1. 帶入ActionListener,
2. onSuccess是指 “開始尋找裝置” 這件事有成功
requestPeers()
requestPeers() & PeerListListener
Connect()
Connect()
Socket stream
成功進行資料連
階層(mac addr)
連線之後. 如果
要使用串流進行
多媒體傳輸的話,
就要建立socket
物件了。
2. 接著 server, client會分別
建立 server Socket, client
Socket
1. 在兩個device進行p2p連
線後,會形成一個group,
系統會指派一個group
owner,或可以在程式中指
定誰要當group owner,在這
個範例中,我們指定"發起
連線端"為client, 另一端則
為 server(group owner)
3. client side就需要用到
WifiP2pInfo 來得到 server的ip,
建立 streaming.
Server socket
Client socket
References
http://chris959.blogspot.tw/2012/04/wifi-
direct.html

More Related Content

Viewers also liked

Wifi chat code explaination
Wifi chat code explainationWifi chat code explaination
Wifi chat code explainationgeniushkg
 
Introduction to Wi-Fi Direct
Introduction to Wi-Fi DirectIntroduction to Wi-Fi Direct
Introduction to Wi-Fi DirectWei-Tsung Su
 
BoscoChat(A Free Wi-Fi Chat Room in Android)
BoscoChat(A Free Wi-Fi Chat Room in Android)BoscoChat(A Free Wi-Fi Chat Room in Android)
BoscoChat(A Free Wi-Fi Chat Room in Android)Samaresh Debbarma
 
A project report on chat application
A project report on chat applicationA project report on chat application
A project report on chat applicationKumar Gaurav
 
Boscochat- A free Wi-Fi ChatRoom in android final documentation
Boscochat- A free Wi-Fi ChatRoom in android final documentationBoscochat- A free Wi-Fi ChatRoom in android final documentation
Boscochat- A free Wi-Fi ChatRoom in android final documentationSamaresh Debbarma
 
Efficient and stable route selection by using cross layer concept for highly...
 Efficient and stable route selection by using cross layer concept for highly... Efficient and stable route selection by using cross layer concept for highly...
Efficient and stable route selection by using cross layer concept for highly...Roopali Singh
 
Network news transport protocol
Network news transport protocolNetwork news transport protocol
Network news transport protocolzxc920903
 
A survey on different cross layer attacks and their defenses in manets
A survey on different cross layer attacks and their defenses in manetsA survey on different cross layer attacks and their defenses in manets
A survey on different cross layer attacks and their defenses in manetsKhaleel Husain
 
HANDLING CROSS-LAYER ATTACKS USING NEIGHBORS MONITORING SCHEME AND SWARM INTE...
HANDLING CROSS-LAYER ATTACKS USING NEIGHBORS MONITORING SCHEME AND SWARM INTE...HANDLING CROSS-LAYER ATTACKS USING NEIGHBORS MONITORING SCHEME AND SWARM INTE...
HANDLING CROSS-LAYER ATTACKS USING NEIGHBORS MONITORING SCHEME AND SWARM INTE...Editor IJCATR
 
Ctcp a cross layer information based tcp for manet
Ctcp  a cross layer information based tcp for manetCtcp  a cross layer information based tcp for manet
Ctcp a cross layer information based tcp for manetijasuc
 
Transport layer protocol for urgent data transmission in wsn
Transport layer protocol for urgent data transmission in wsnTransport layer protocol for urgent data transmission in wsn
Transport layer protocol for urgent data transmission in wsneSAT Journals
 
Image transport protocol itp(synopsis)
Image transport protocol itp(synopsis)Image transport protocol itp(synopsis)
Image transport protocol itp(synopsis)Mumbai Academisc
 
Improved Video Transmission over MANETs using MDSR with MDC
Improved Video Transmission over MANETs using MDSR with MDCImproved Video Transmission over MANETs using MDSR with MDC
Improved Video Transmission over MANETs using MDSR with MDCijsrd.com
 
Vertical handoff and TCP performance optimizations using cross layer approach
Vertical handoff and TCP performance optimizations using cross layer approachVertical handoff and TCP performance optimizations using cross layer approach
Vertical handoff and TCP performance optimizations using cross layer approachAnurag Mondal
 
Wifi Direct on Android - GDG Campinas
Wifi Direct on Android - GDG CampinasWifi Direct on Android - GDG Campinas
Wifi Direct on Android - GDG CampinasRenato Freire Ricardo
 
Qo s provisioning for scalable video streaming over ad hoc networks using cro...
Qo s provisioning for scalable video streaming over ad hoc networks using cro...Qo s provisioning for scalable video streaming over ad hoc networks using cro...
Qo s provisioning for scalable video streaming over ad hoc networks using cro...Mshari Alabdulkarim
 
Wifi direct technology a technical report
Wifi direct technology   a technical reportWifi direct technology   a technical report
Wifi direct technology a technical reportAngelos Alevizopoulos
 
Cross Layer- Performance Enhancement Architecture (CL-PEA) for MANET
Cross Layer- Performance Enhancement Architecture (CL-PEA) for MANETCross Layer- Performance Enhancement Architecture (CL-PEA) for MANET
Cross Layer- Performance Enhancement Architecture (CL-PEA) for MANETijcncs
 
WiFi Direct with Delay-Optimized DTN is the Base Recipe for Applications in L...
WiFi Direct with Delay-Optimized DTN is the Base Recipe for Applications in L...WiFi Direct with Delay-Optimized DTN is the Base Recipe for Applications in L...
WiFi Direct with Delay-Optimized DTN is the Base Recipe for Applications in L...Tokyo University of Science
 

Viewers also liked (20)

Wifi chat code explaination
Wifi chat code explainationWifi chat code explaination
Wifi chat code explaination
 
Introduction to Wi-Fi Direct
Introduction to Wi-Fi DirectIntroduction to Wi-Fi Direct
Introduction to Wi-Fi Direct
 
BoscoChat(A Free Wi-Fi Chat Room in Android)
BoscoChat(A Free Wi-Fi Chat Room in Android)BoscoChat(A Free Wi-Fi Chat Room in Android)
BoscoChat(A Free Wi-Fi Chat Room in Android)
 
A project report on chat application
A project report on chat applicationA project report on chat application
A project report on chat application
 
Boscochat- A free Wi-Fi ChatRoom in android final documentation
Boscochat- A free Wi-Fi ChatRoom in android final documentationBoscochat- A free Wi-Fi ChatRoom in android final documentation
Boscochat- A free Wi-Fi ChatRoom in android final documentation
 
Efficient and stable route selection by using cross layer concept for highly...
 Efficient and stable route selection by using cross layer concept for highly... Efficient and stable route selection by using cross layer concept for highly...
Efficient and stable route selection by using cross layer concept for highly...
 
Network news transport protocol
Network news transport protocolNetwork news transport protocol
Network news transport protocol
 
A survey on different cross layer attacks and their defenses in manets
A survey on different cross layer attacks and their defenses in manetsA survey on different cross layer attacks and their defenses in manets
A survey on different cross layer attacks and their defenses in manets
 
HANDLING CROSS-LAYER ATTACKS USING NEIGHBORS MONITORING SCHEME AND SWARM INTE...
HANDLING CROSS-LAYER ATTACKS USING NEIGHBORS MONITORING SCHEME AND SWARM INTE...HANDLING CROSS-LAYER ATTACKS USING NEIGHBORS MONITORING SCHEME AND SWARM INTE...
HANDLING CROSS-LAYER ATTACKS USING NEIGHBORS MONITORING SCHEME AND SWARM INTE...
 
Ctcp a cross layer information based tcp for manet
Ctcp  a cross layer information based tcp for manetCtcp  a cross layer information based tcp for manet
Ctcp a cross layer information based tcp for manet
 
Transport layer protocol for urgent data transmission in wsn
Transport layer protocol for urgent data transmission in wsnTransport layer protocol for urgent data transmission in wsn
Transport layer protocol for urgent data transmission in wsn
 
Image transport protocol itp(synopsis)
Image transport protocol itp(synopsis)Image transport protocol itp(synopsis)
Image transport protocol itp(synopsis)
 
Improved Video Transmission over MANETs using MDSR with MDC
Improved Video Transmission over MANETs using MDSR with MDCImproved Video Transmission over MANETs using MDSR with MDC
Improved Video Transmission over MANETs using MDSR with MDC
 
Vertical handoff and TCP performance optimizations using cross layer approach
Vertical handoff and TCP performance optimizations using cross layer approachVertical handoff and TCP performance optimizations using cross layer approach
Vertical handoff and TCP performance optimizations using cross layer approach
 
Wifi Direct on Android - GDG Campinas
Wifi Direct on Android - GDG CampinasWifi Direct on Android - GDG Campinas
Wifi Direct on Android - GDG Campinas
 
Qo s provisioning for scalable video streaming over ad hoc networks using cro...
Qo s provisioning for scalable video streaming over ad hoc networks using cro...Qo s provisioning for scalable video streaming over ad hoc networks using cro...
Qo s provisioning for scalable video streaming over ad hoc networks using cro...
 
Wifi direct technology a technical report
Wifi direct technology   a technical reportWifi direct technology   a technical report
Wifi direct technology a technical report
 
Cross Layer- Performance Enhancement Architecture (CL-PEA) for MANET
Cross Layer- Performance Enhancement Architecture (CL-PEA) for MANETCross Layer- Performance Enhancement Architecture (CL-PEA) for MANET
Cross Layer- Performance Enhancement Architecture (CL-PEA) for MANET
 
WiFi Direct with Delay-Optimized DTN is the Base Recipe for Applications in L...
WiFi Direct with Delay-Optimized DTN is the Base Recipe for Applications in L...WiFi Direct with Delay-Optimized DTN is the Base Recipe for Applications in L...
WiFi Direct with Delay-Optimized DTN is the Base Recipe for Applications in L...
 
Mobile Communication
Mobile CommunicationMobile Communication
Mobile Communication
 

Similar to WiFi direct

想與家中的數據機或分享器連線,但是既有的設備沒有Wps按鍵,怎麼辦?
想與家中的數據機或分享器連線,但是既有的設備沒有Wps按鍵,怎麼辦?想與家中的數據機或分享器連線,但是既有的設備沒有Wps按鍵,怎麼辦?
想與家中的數據機或分享器連線,但是既有的設備沒有Wps按鍵,怎麼辦?臺灣塔米歐
 
Appium手机自动化测试 testerhome_bqcon版本
Appium手机自动化测试 testerhome_bqcon版本Appium手机自动化测试 testerhome_bqcon版本
Appium手机自动化测试 testerhome_bqcon版本延胜 黄
 
Avaya统一通信主打胶片
Avaya统一通信主打胶片Avaya统一通信主打胶片
Avaya统一通信主打胶片abcd098123
 
Presentation 201411
Presentation  201411Presentation  201411
Presentation 201411kentsi
 
好管房~遠端管理房間的服務
好管房~遠端管理房間的服務 好管房~遠端管理房間的服務
好管房~遠端管理房間的服務 Johnny Hwang
 
行動與雲端科技在圖書館的應用
行動與雲端科技在圖書館的應用行動與雲端科技在圖書館的應用
行動與雲端科技在圖書館的應用皓仁 柯
 
yarlungsoft Business Plan 5.1_introduction
yarlungsoft Business Plan 5.1_introductionyarlungsoft Business Plan 5.1_introduction
yarlungsoft Business Plan 5.1_introductionLeon Liu
 
GMIC 2012 - Baidu, Presentation by Mr Wang Jin, 百度副总裁王劲
GMIC 2012 - Baidu, Presentation by Mr Wang Jin, 百度副总裁王劲GMIC 2012 - Baidu, Presentation by Mr Wang Jin, 百度副总裁王劲
GMIC 2012 - Baidu, Presentation by Mr Wang Jin, 百度副总裁王劲Great Wall Club
 
胡桃宇宙公司簡報20210625
胡桃宇宙公司簡報20210625胡桃宇宙公司簡報20210625
胡桃宇宙公司簡報20210625Johnny Hwang
 
2013 phind corp. 公司簡介
2013 phind corp. 公司簡介2013 phind corp. 公司簡介
2013 phind corp. 公司簡介Chia-Yu Kuo
 
HTML5 生态系统和应用架构模型
HTML5 生态系统和应用架构模型HTML5 生态系统和应用架构模型
HTML5 生态系统和应用架构模型Tom Fan
 
20130823 優網通產品發表會-hisb介紹
20130823 優網通產品發表會-hisb介紹20130823 優網通產品發表會-hisb介紹
20130823 優網通產品發表會-hisb介紹HermesDDS
 
Service Integration Workshop
Service Integration WorkshopService Integration Workshop
Service Integration WorkshopRyan Chung
 
441 网思商业计划书
441 网思商业计划书441 网思商业计划书
441 网思商业计划书Rui (Nash) Yang
 
20140610 net tuesday - 行動裝置安全
20140610 net tuesday - 行動裝置安全20140610 net tuesday - 行動裝置安全
20140610 net tuesday - 行動裝置安全Net Tuesday Taiwan
 
Network security reesjohnson
Network security reesjohnsonNetwork security reesjohnson
Network security reesjohnsonITband
 
Touch开发应届生培训
Touch开发应届生培训Touch开发应届生培训
Touch开发应届生培训Zhi Zhong
 
Windows Phone 7 in azure
Windows Phone 7 in azureWindows Phone 7 in azure
Windows Phone 7 in azureTao Wang
 

Similar to WiFi direct (20)

想與家中的數據機或分享器連線,但是既有的設備沒有Wps按鍵,怎麼辦?
想與家中的數據機或分享器連線,但是既有的設備沒有Wps按鍵,怎麼辦?想與家中的數據機或分享器連線,但是既有的設備沒有Wps按鍵,怎麼辦?
想與家中的數據機或分享器連線,但是既有的設備沒有Wps按鍵,怎麼辦?
 
Appium手机自动化测试 testerhome_bqcon版本
Appium手机自动化测试 testerhome_bqcon版本Appium手机自动化测试 testerhome_bqcon版本
Appium手机自动化测试 testerhome_bqcon版本
 
Avaya统一通信主打胶片
Avaya统一通信主打胶片Avaya统一通信主打胶片
Avaya统一通信主打胶片
 
Presentation 201411
Presentation  201411Presentation  201411
Presentation 201411
 
行動技術開發概論
行動技術開發概論行動技術開發概論
行動技術開發概論
 
好管房~遠端管理房間的服務
好管房~遠端管理房間的服務 好管房~遠端管理房間的服務
好管房~遠端管理房間的服務
 
行動與雲端科技在圖書館的應用
行動與雲端科技在圖書館的應用行動與雲端科技在圖書館的應用
行動與雲端科技在圖書館的應用
 
Cu见你
Cu见你Cu见你
Cu见你
 
yarlungsoft Business Plan 5.1_introduction
yarlungsoft Business Plan 5.1_introductionyarlungsoft Business Plan 5.1_introduction
yarlungsoft Business Plan 5.1_introduction
 
GMIC 2012 - Baidu, Presentation by Mr Wang Jin, 百度副总裁王劲
GMIC 2012 - Baidu, Presentation by Mr Wang Jin, 百度副总裁王劲GMIC 2012 - Baidu, Presentation by Mr Wang Jin, 百度副总裁王劲
GMIC 2012 - Baidu, Presentation by Mr Wang Jin, 百度副总裁王劲
 
胡桃宇宙公司簡報20210625
胡桃宇宙公司簡報20210625胡桃宇宙公司簡報20210625
胡桃宇宙公司簡報20210625
 
2013 phind corp. 公司簡介
2013 phind corp. 公司簡介2013 phind corp. 公司簡介
2013 phind corp. 公司簡介
 
HTML5 生态系统和应用架构模型
HTML5 生态系统和应用架构模型HTML5 生态系统和应用架构模型
HTML5 生态系统和应用架构模型
 
20130823 優網通產品發表會-hisb介紹
20130823 優網通產品發表會-hisb介紹20130823 優網通產品發表會-hisb介紹
20130823 優網通產品發表會-hisb介紹
 
Service Integration Workshop
Service Integration WorkshopService Integration Workshop
Service Integration Workshop
 
441 网思商业计划书
441 网思商业计划书441 网思商业计划书
441 网思商业计划书
 
20140610 net tuesday - 行動裝置安全
20140610 net tuesday - 行動裝置安全20140610 net tuesday - 行動裝置安全
20140610 net tuesday - 行動裝置安全
 
Network security reesjohnson
Network security reesjohnsonNetwork security reesjohnson
Network security reesjohnson
 
Touch开发应届生培训
Touch开发应届生培训Touch开发应届生培训
Touch开发应届生培训
 
Windows Phone 7 in azure
Windows Phone 7 in azureWindows Phone 7 in azure
Windows Phone 7 in azure
 

More from Roy Chen

The Power of Variable Names
The Power of Variable NamesThe Power of Variable Names
The Power of Variable NamesRoy Chen
 
培養深度工作力
培養深度工作力培養深度工作力
培養深度工作力Roy Chen
 
Svm and libsvm
Svm  and libsvmSvm  and libsvm
Svm and libsvmRoy Chen
 
Phonegap入門
Phonegap入門Phonegap入門
Phonegap入門Roy Chen
 
Nfc tutorial
Nfc tutorialNfc tutorial
Nfc tutorialRoy Chen
 
Cloud service and gae for java(gae:j)
Cloud service and gae for java(gae:j)Cloud service and gae for java(gae:j)
Cloud service and gae for java(gae:j)Roy Chen
 
Processing for fun
Processing for funProcessing for fun
Processing for funRoy Chen
 
聽障朋友科技應用
聽障朋友科技應用聽障朋友科技應用
聽障朋友科技應用Roy Chen
 
Phonegap tricky
Phonegap trickyPhonegap tricky
Phonegap trickyRoy Chen
 

More from Roy Chen (11)

The Power of Variable Names
The Power of Variable NamesThe Power of Variable Names
The Power of Variable Names
 
培養深度工作力
培養深度工作力培養深度工作力
培養深度工作力
 
Svm and libsvm
Svm  and libsvmSvm  and libsvm
Svm and libsvm
 
Phonegap入門
Phonegap入門Phonegap入門
Phonegap入門
 
Nfc tutorial
Nfc tutorialNfc tutorial
Nfc tutorial
 
Gwt rpc
Gwt rpcGwt rpc
Gwt rpc
 
Cloud service and gae for java(gae:j)
Cloud service and gae for java(gae:j)Cloud service and gae for java(gae:j)
Cloud service and gae for java(gae:j)
 
Processing for fun
Processing for funProcessing for fun
Processing for fun
 
個資法
個資法個資法
個資法
 
聽障朋友科技應用
聽障朋友科技應用聽障朋友科技應用
聽障朋友科技應用
 
Phonegap tricky
Phonegap trickyPhonegap tricky
Phonegap tricky
 

WiFi direct

Editor's Notes

  1. 這四種intent下一頁會介紹是什麼
  2. 範例中把 broadcast receiver 註冊在 main activity中的 onResume 如果收到 CONNECTION_CHANGED 的 intent action, 有可能的情況是, 成功建立p2p連線 (data link layer by mac addr)後丟出此intent, broadcast receiver接到後, 接著可能會做建立socket連線的動作。 收到THIS_DEVICE_CHANGED 的話,有可能是本機的一些資訊有改變,像是裝置名稱改變。 STATE_CHANGED, 則是wifi enable是否有被你打開 PEERS_CHANGED, 則是當偵測到有新的peer list時,會丟出這個intent, 這時可以去requestPeers()把實際的list拿到
  3. discoverPeers() 要帶入一個 ActionListener為參數, 然後可以再成功與失敗的callback裡做對應的動作。 onSuccess(){} 指的是 “開始尋找device” 這件事情有成功,所以在function裡加上“開始尋找”的文字提示。 假設有搜尋到 p2p的wifi device, 系統會丟出一個含有 "WIFI_P2P_PEERS_CHANGED_ACTION" 的intent, 此時之前寫好的BroadCast Receiver就會接住這個intent, 並做處理。 注意!! 這個intent並沒有附加p2p device的list, 這個intent只是告訴你有搜尋到新的p2p device.
  4. discoverPeers() 要帶入一個 ActionListener為參數, 然後可以再成功與失敗的callback裡做對應的動作。 onSuccess(){} 指的是 “開始尋找device” 這件事情有成功,所以在function裡加上“開始尋找”的文字提示。 假設有搜尋到 p2p的wifi device, 系統會丟出一個含有 "WIFI_P2P_PEERS_CHANGED_ACTION" 的intent, 此時之前寫好的BroadCast Receiver就會接住這個intent, 並做處理。 注意!! 這個intent並沒有附加p2p device的list, 這個intent只是告訴你有搜尋到新的p2p device.
  5. 1.在收到 "WIFI_P2P_PEERS_CHANGED_ACTION"後,通常會去呼叫 requestPeers(), 因為這個方法才能真正讓你得到一組可以進行p2p link的 list 2. requestPeers() 也是個非同步的方法,需要帶入PeerListListener為參數,onPeersAvailable則是它的callback function,在onPeersAvailable裡面可以得到新的 peersList (如果有的話) 3.這個peerList裡有說明: 搜尋到幾個device, device分別的detail又是什麼? (這裡的detaild可能像是 mac address...等等)
  6. 我們由 requestPeers得到了peerlist,和每個peer的資訊,現在可以用connet()來進行連線 這個階段是用mac address來連線, 要在connect傳入一個 Wifip2pCinfug物件, 這個物件包含了另一個device的mac addr. 這裡的 onSuccess() 是指 “成功發送一個request” 這件事, 並不是真的成功建立雙方間的連線 真正的建立連線是指對方按下同意,接著系統會丟出WIFI_P2P_CONNECTION_CHANGED_ACTION 的intent, 再由broadcast receiver做處理。