Download - Networking in Windows Phone 8
![Page 1: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/1.jpg)
![Page 2: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/2.jpg)
Networking in Windows Phone 8
Peter TorrProgram Manager, Windows Phone Developer Platform2-222
![Page 3: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/3.jpg)
Agenda
HTTP
Sockets
Proximity
Tips and Tricks
![Page 4: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/4.jpg)
Choosing the Right API
![Page 5: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/5.jpg)
Windows 8.x
Legacy C++
Desktop .NET
Windows Phone 7.xHttpWebRequest
WebClient
.NET Sockets
.NET HttpClient
WinRT Sockets
WCF
Win
dow
s Ph
one 8
Pla
tform
WinSock
IXmlHttpRequest2
![Page 6: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/6.jpg)
WinRT Sockets
IXmlHttpRequest2
WinRT Sockets
.NET HttpClient
.NET
C++
Win
dow
s Ph
one 8
Pla
tform
![Page 7: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/7.jpg)
Setting up your Development Machine
![Page 8: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/8.jpg)
Step 1: Get your IPv4 address
From elevated command prompt
C:\>ipconfig
Windows IP Configuration
Ethernet adapter vEthernet (don't pick the Emulator): [...] IPv4 Address. . . . . . . . . . . : 192.168.0.123
![Page 9: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/9.jpg)
Step 2: Add binding for IISExpress
Update the IISExpress config file%userprofile%\Documents\IISExpress\config\applicationhost.config
<site name="TestApp" id="1"> <...> <binding protocol="http" bindingInformation="*:45678:localhost" /> <binding protocol="http" bindingInformation="*:45678:192.168.0.123" />
![Page 10: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/10.jpg)
Step 3: Add reservation for http.sys
From elevated command-prompt:
C:\>netsh http add urlacl url=http://192.168.0.123:45678/ user=everyone
![Page 11: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/11.jpg)
Step 4: Enable traffic through firewall
From elevated command-prompt:
C:\>netsh advfirewall firewall add rule dir=in action=allow protocol=tcp localport=45678 remoteip=localsubnet profile=private,domain name=TestApp
![Page 12: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/12.jpg)
HTTP APIs
![Page 13: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/13.jpg)
.NET HttpClient
Simple, modern API based on async pattern
Built in to .NET 4.5 and Windows 8
NuGet package for Windows Phone 7.5 and 8
“Pipeline” model for filters, mocks, and more
![Page 14: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/14.jpg)
IXmlHttpRequest2
Mature COM API
Built in to Windows 8 and Windows Phone 8
Only HTTP stack available to native
![Page 15: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/15.jpg)
DEMOHTTP APIs
![Page 16: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/16.jpg)
Socket and Proximity APIs
![Page 17: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/17.jpg)
WinRT Sockets
Simple, modern API based on async pattern
Built in to Windows 8 and Windows Phone 8
Stream- and Datagram- based (no WebSockets on Phone)
Support for client and server scenarios
![Page 18: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/18.jpg)
DEMOStreamSocket
![Page 19: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/19.jpg)
Proximity
Abstraction over NFC, Bluetooth, and WiFi
Built in to Windows 8 and Windows Phone 8
Enables P2P gaming, transfers, etc. (NFC has other uses)
Once connected, uses StreamSocket for communication
![Page 20: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/20.jpg)
Cinemagraph by
NokiaProximity Demo
![Page 21: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/21.jpg)
Proximity Flowchart - Host
Start
Look for peers
Tap other phone
Magic Happens
Connected StreamSocke
t
Connect to peer
Browse for peers
Tap + Play
![Page 22: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/22.jpg)
Proximity Flowchart - Client
Start
Launched via tap
Magic Happens
Connected StreamSocke
t
Browse for peers
Tap + Play
Wait for peer
Connect to peer
![Page 23: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/23.jpg)
DEMOProximity
![Page 24: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/24.jpg)
Tips and Tricks
![Page 25: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/25.jpg)
Tips from today
Setup your dev machine for each new project
Use the pre-release version of WebAPI Client Libraries
Plan your proximity connection experience before you code
Hookup PeerFinder events before calling Start()
![Page 26: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/26.jpg)
Tips from today
Remove <meta> tags for WebBrowser.NavigateToString
Copy the Windows SDK code for IXmlHttpRequest2Always code your web sites in orange Comic Sans MS
![Page 27: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/27.jpg)
Feed Reader by Sam Jarawan
HttpWebRequest works; use HttpClient if rebuilding today
Prefer Json .NET over built-in serializer for complex objects
Consider WebBrowser vs custom XAML UX trade-off
![Page 28: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/28.jpg)
Engadget
Uses background agent to pre-load data
Great for jumping on an aeroplane or slow connections
Also just a great UX in general vs. basic web browser
![Page 29: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/29.jpg)
Other Tips from Popular Apps
Build a priority queue for requests if you have lots going on
Use the new HttpClient.Compression NuGet package
Validate your URIs if dynamically generating them
Use network simulator in Visual Studio
![Page 30: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/30.jpg)
Wrap-Up
![Page 31: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/31.jpg)
Agenda
HTTP – HttpClient (managed); IXmlHttpRequest2 (native)
Sockets – WinRT Sockets
Proximity – Browse vs. Tap; PeerFinder & WinRT Sockets
Tips and Tricks – dev setup, JSON, compression, agents
and always use Comic Sans MS
![Page 32: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/32.jpg)
Other Resources
2-211 Native Code: Tim Laverty - South 102 @ 10:302-212 App2App: Sean McKenna - South 222 @ 2:002-220 Maps: Mike O’Malley - Here (North 134) @ 2:00
2-215 Build for Both: Matt Hidinger - View online3-548 Phone + Azure: Yvor Georgiev - View online4-092 WinRT HttpClient: Peter Smith - View online3-057 Networking: Tim Laverty (//Build/ 2012) - View online
![Page 33: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/33.jpg)
Evaluate this session
Scan this QR code to evaluate this session and be automatically entered in a drawing to win a prize!
![Page 34: Networking in Windows Phone 8](https://reader035.vdocument.in/reader035/viewer/2022070403/568139d9550346895da18ce3/html5/thumbnails/34.jpg)
© 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.