SlideShare a Scribd company logo
1 of 27
Download to read offline
Consulting/Training
Windows 8.1 Sockets
Consulting/Training
consulting
Wintellect helps you build better software,
faster, tackling the tough projects and solving
the software and technology questions that
help you transform your business.
 Architecture, Analysis and Design
 Full lifecycle software development
 Debugging and Performance tuning
 Database design and development
training
Wintellect's courses are written and taught by
some of the biggest and most respected names
in the Microsoft programming industry.
 Learn from the best. Access the same
training Microsoft’s developers enjoy
 Real world knowledge and solutions on
both current and cutting edge
technologies
 Flexibility in training options – onsite,
virtual, on demand
Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins – we pull
out all the stops to help our customers achieve their goals through advanced software-based
consulting and training solutions.
who we are
About Wintellect
Consulting/Training
 Sockets, Simplified
 WebSockets
 UDP and TCP Sockets
 Proximity / NFC “Tap to Connect”
 Bluetooth and Wi-Fi Direct
 Recap
Agenda
Consulting/Training
 Covers full WinRT API
 Over 80 example
projects
 This presentation is
based on Chapter 10
 Full source online at
http://winrtexamples
.codeplex.com/
 Book available at
http://bit.ly/winrtxmpl
WinRT by Example
Consulting/Training
Sockets, Simplified
Byte
Consulting/Training
Sockets, Simplified
Byte Array
Consulting/Training
Sockets, Simplified
Stream
 Length (maybe)
 Position
 Read
 Write
 Seek
Consulting/Training
Sockets Are Specialized Streams
Consulting/Training
 Berkeley sockets released with Unix in 1983 (owned by
AT&T at the time) for “IPC” while I was writing my first
Commodore 64 programs in 6502 assembly
 Open licensing in 1989 (I had finally moved to IBM PC and
MS-DOS)
 POSIX API (Portable Operating System Interface) released
in 1988
 Windows Sockets API (WSA or Winsock) released in 1992 (I
graduated high school and discovered the Internet in
college) and later implemented for Windows
 Another F Ancillary Function Driver (AFD.sys) still exists to
this day
Sockets: A Brief History
Consulting/Training
Sockets Are Specialized Streams
Consulting/Training
Sockets Are Specialized Streams
Consulting/Training
 A way to communicate between end points
 Usually operate on streams, which are
abstractions over buffers that contain bytes
 But can be a datagram that has no connection
 A socket connection has two distinct end points
 An end point is a combination of an address and
a port
 End points can be hosted on the same machine,
or different machines
Sockets Recap
Consulting/Training
int main(void)
{
struct sockaddr_in stSockAddr;
int Res;
int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (-1 == SocketFD)
{
perror("cannot create socket");
exit(EXIT_FAILURE);
}
memset(&stSockAddr, 0, sizeof(stSockAddr));
stSockAddr.sin_family = AF_INET;
stSockAddr.sin_port = htons(1100);
Res = inet_pton(AF_INET, "192.168.1.1", &stSockAddr.sin_addr);
(void) shutdown(SocketFD, SHUT_RDWR);
close(SocketFD);
return EXIT_SUCCESS;
}
“The Old Days” (still valid 30 yrs. later)
Consulting/Training
 Sit on top of TCP (you’ll learn more about TCP
later)
 Operate over ports 80/443 by default (keeps
firewalls happy)
 Use HTTP for the initial “handshake”
 Provide full-duplex communications
 WinRT implementation allows for message-
based or stream-based
WebSockets
Consulting/Training
GET /info HTTP/1.1
HOST: 1.2.3.4
Upgrade: websocket
Connection: Upgrade
Origin: http://jeremylikness.com/
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
WebSocket Handshake
Placing my call …
Accepting ….
Now it’s streams from here on out….
Consulting/Training
(a prime example… source code: http://bit.ly/1i5vB9p)
WebSockets
Consulting/Training
 Both are communication protocols for delivering
octet streams (bytes!)
 UDP is fire-and-forget (connectionless)
 Individual messages sent, i.e. “datagrams”
 Fast, lots of questions: DNS, DHCP, SNMP
 TCP is connection-oriented
 TCP is stream-based
 Slower, but reliable: HTTP, FTP, SMTP, Telnet
UDP and TCP
Consulting/Training
this.serverSocket = new StreamSocketListener();
this.serverSocket.ConnectionReceived +=
this.ServerSocketConnectionReceived;
await this.serverSocket.BindServiceNameAsync(ServiceName);
// can both read and write messages (full-duplex)
if (serverWriter == null)
{
serverWriter = new DataWriter(args.Socket.OutputStream);
serverReader = new DataReader(args.Socket.InputStream);
}
Server Listens for Connections
Consulting/Training
var hostName = new HostName("localhost");
this.clientSocket = new StreamSocket();
await this.clientSocket.ConnectAsync(hostName, ServiceName);
clientWriter = new DataWriter(this.clientSocket.OutputStream);
clientReader = new DataReader(this.clientSocket.InputStream);
// both client and server require long-running tasks to wait for
// messages and send them as needed
while (true)
{
var data = await GetStringFromReader(clientReader);
// do something with the data
}
Client “Dials In” to Chat
Consulting/Training
(a true adventure… source code: http://bit.ly/1j77rP3)
TCP Sockets
Consulting/Training
 Near Field Communications (NFC) is a standard for extremely low powered
communications typically very slow and over a very small distance, between devices
and/or smart tags
 NFC is capable of sending small bursts of information. However, “tap to connect” is a
powerful mechanism for establishing a hand-shake to open a stream over other,
longer range and faster protocols like Bluetooth and Wi-Fi Direct
 Windows Runtime exposes the Proximity APIs that provide a unified way to discover
nearby devices and a protocol-agnostic mechanism to connect
 Literally you can discover, handshake, etc. and WinRT will “hand-off” a socket that is
ready to use (you won’t even know if it is over Wi-Fi Direct or Bluetooth)
 Bluetooth = short wavelength wireless technology
 Wi-Fi Direct = peer to peer over Wi-Fi (wireless cards without requiring a wireless
access point or router)
NFC and Proximity
Consulting/Training
this.proximityDevice = ProximityDevice.GetDefault();
this.proximityDevice.DeviceArrived +=
this.ProximityDeviceDeviceArrived;
this.proximityDevice.DeviceDeparted +=
this.ProximityDeviceDeviceDeparted;
PeerFinder.ConnectionRequested +=
this.PeerFinderConnectionRequested;
PeerFinder.Role = PeerRole.Peer;
PeerFinder.Start();
var peers = await PeerFinder.FindAllPeersAsync();
var socket = await
PeerFinder.ConnectAsync(this.SelectedPeer.Information);
Proximity APIs
NFC device and events
Peer Finder (listen and browse)
Browse for peers
Connect to peer
Consulting/Training
1. Try to get Proximity Device (NFC)
2. If exists, register to enter/leave events (NFC)
3. If it supports triggers (i.e. tap) register for connection
state change event (NFC)
4. Otherwise browse for peers (Wi-Fi Direct, Bluetooth)
5. When a peer is found, send a connection request
6. Peer must accept the connection request
7. In any scenario, once the connection exists you are
passed a stream socket and are free to communicate
Steps for Proximity
Consulting/Training
Source code: http://bit.ly/1jlnGbB
Proximity
Consulting/Training
 WebSockets API for simplified WebSockets
 Sockets API for TCP, UDP, Bluetooth, Wi-Fi Direct
 Windows 8.1 is capable of dialing out to any
address and port
 As a server, most practical example is listening
for Bluetooth connections
 The security sandbox prevents using sockets for
inter-app communications
Recap
Consulting/Training
Subscribers Enjoy
 Expert Instructors
 Quality Content
 Practical Application
 All Devices
Wintellect’s On-Demand
Video Training Solution
Individuals | Businesses | Enterprise Organizations
WintellectNOW.com
Authors Enjoy
 Royalty Income
 Personal Branding
 Free Library Access
 Cross-Sell
Opportunities
Try It Free!
Use Promo Code:
LIKNESS-13
Consulting/Training
http://winrtexamples.codeplex.com/
http://bit.ly/winrtxmpl
Questions?

More Related Content

What's hot

Play with Angular JS
Play with Angular JSPlay with Angular JS
Play with Angular JSKnoldus Inc.
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by GoogleASG
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Marco Breveglieri
 
PHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterPHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterKHALID C
 
Java Technology
Java TechnologyJava Technology
Java Technologyifnu bima
 
A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!Muhammad Ghazali
 
Php Frameworks
Php FrameworksPhp Frameworks
Php FrameworksRyan Davis
 
MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModelDareen Alhiyari
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code IgniterAmzad Hossain
 
Dev212 Comparing Net And Java The View From 2006
Dev212 Comparing  Net And Java  The View From 2006Dev212 Comparing  Net And Java  The View From 2006
Dev212 Comparing Net And Java The View From 2006kkorovkin
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
MVC Frameworks for building PHP Web Applications
MVC Frameworks for building PHP Web ApplicationsMVC Frameworks for building PHP Web Applications
MVC Frameworks for building PHP Web ApplicationsVforce Infotech
 
Java script performance tips
Java script performance tipsJava script performance tips
Java script performance tipsShakti Shrestha
 
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-ControllerAction-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-ControllerPaul Jones
 
Introduction to web compoents
Introduction to web compoentsIntroduction to web compoents
Introduction to web compoentsRan Wahle
 
MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009Jonas Follesø
 
React JS Interview Question & Answer
React JS Interview Question & AnswerReact JS Interview Question & Answer
React JS Interview Question & AnswerMildain Solutions
 
Spring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVCSpring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVCHitesh-Java
 

What's hot (20)

Play with Angular JS
Play with Angular JSPlay with Angular JS
Play with Angular JS
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
 
PHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterPHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniter
 
Java Technology
Java TechnologyJava Technology
Java Technology
 
JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...
JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...
JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...
 
A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!
 
04 managing the database
04   managing the database04   managing the database
04 managing the database
 
Php Frameworks
Php FrameworksPhp Frameworks
Php Frameworks
 
MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModel
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 
Dev212 Comparing Net And Java The View From 2006
Dev212 Comparing  Net And Java  The View From 2006Dev212 Comparing  Net And Java  The View From 2006
Dev212 Comparing Net And Java The View From 2006
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
MVC Frameworks for building PHP Web Applications
MVC Frameworks for building PHP Web ApplicationsMVC Frameworks for building PHP Web Applications
MVC Frameworks for building PHP Web Applications
 
Java script performance tips
Java script performance tipsJava script performance tips
Java script performance tips
 
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-ControllerAction-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
 
Introduction to web compoents
Introduction to web compoentsIntroduction to web compoents
Introduction to web compoents
 
MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009
 
React JS Interview Question & Answer
React JS Interview Question & AnswerReact JS Interview Question & Answer
React JS Interview Question & Answer
 
Spring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVCSpring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVC
 

Viewers also liked

Angular from a Different Angle
Angular from a Different AngleAngular from a Different Angle
Angular from a Different AngleJeremy Likness
 
Advanced AngularJS Tips and Tricks
Advanced AngularJS Tips and TricksAdvanced AngularJS Tips and Tricks
Advanced AngularJS Tips and TricksJeremy Likness
 
Let's Build an Angular App!
Let's Build an Angular App!Let's Build an Angular App!
Let's Build an Angular App!Jeremy Likness
 
Angle Forward with TypeScript
Angle Forward with TypeScriptAngle Forward with TypeScript
Angle Forward with TypeScriptJeremy Likness
 
C# Async/Await Explained
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await ExplainedJeremy Likness
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Jeremy Likness
 
Back to the ng2 Future
Back to the ng2 FutureBack to the ng2 Future
Back to the ng2 FutureJeremy Likness
 
Cross-Platform Agile DevOps with Visual Studio Team Services
Cross-Platform Agile DevOps with Visual Studio Team ServicesCross-Platform Agile DevOps with Visual Studio Team Services
Cross-Platform Agile DevOps with Visual Studio Team ServicesJeremy Likness
 

Viewers also liked (8)

Angular from a Different Angle
Angular from a Different AngleAngular from a Different Angle
Angular from a Different Angle
 
Advanced AngularJS Tips and Tricks
Advanced AngularJS Tips and TricksAdvanced AngularJS Tips and Tricks
Advanced AngularJS Tips and Tricks
 
Let's Build an Angular App!
Let's Build an Angular App!Let's Build an Angular App!
Let's Build an Angular App!
 
Angle Forward with TypeScript
Angle Forward with TypeScriptAngle Forward with TypeScript
Angle Forward with TypeScript
 
C# Async/Await Explained
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await Explained
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!
 
Back to the ng2 Future
Back to the ng2 FutureBack to the ng2 Future
Back to the ng2 Future
 
Cross-Platform Agile DevOps with Visual Studio Team Services
Cross-Platform Agile DevOps with Visual Studio Team ServicesCross-Platform Agile DevOps with Visual Studio Team Services
Cross-Platform Agile DevOps with Visual Studio Team Services
 

Similar to Windows 8.1 Sockets

Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with phpElizabeth Smith
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in JavaTushar B Kute
 
Simplified Networking and Troubleshooting for K-12 Teachers
Simplified Networking and Troubleshooting for K-12 TeachersSimplified Networking and Troubleshooting for K-12 Teachers
Simplified Networking and Troubleshooting for K-12 Teacherswebhostingguy
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tourcacois
 
Practical Security with MQTT and Mosquitto
Practical Security with MQTT and MosquittoPractical Security with MQTT and Mosquitto
Practical Security with MQTT and Mosquittonbarendt
 
Puppet Camp Boston 2014: Keynote
Puppet Camp Boston 2014: Keynote Puppet Camp Boston 2014: Keynote
Puppet Camp Boston 2014: Keynote Puppet
 
Networking and communications security – network architecture design
Networking and communications security – network architecture designNetworking and communications security – network architecture design
Networking and communications security – network architecture designEnterpriseGRC Solutions, Inc.
 
FMS Administration Seminar
FMS Administration SeminarFMS Administration Seminar
FMS Administration SeminarYoss Cohen
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagarNitish Nagar
 
Network And Network Address Translation
Network And Network Address TranslationNetwork And Network Address Translation
Network And Network Address TranslationErin Moore
 
Optimizing windows 8 for virtual desktops - teched 2013 Jeff Stokes
Optimizing windows 8 for virtual desktops - teched 2013 Jeff StokesOptimizing windows 8 for virtual desktops - teched 2013 Jeff Stokes
Optimizing windows 8 for virtual desktops - teched 2013 Jeff StokesJeff Stokes
 
Desktop, Embedded and Mobile Apps with PrismTech Vortex Cafe
Desktop, Embedded and Mobile Apps with PrismTech Vortex CafeDesktop, Embedded and Mobile Apps with PrismTech Vortex Cafe
Desktop, Embedded and Mobile Apps with PrismTech Vortex CafeADLINK Technology IoT
 
Desktop, Embedded and Mobile Apps with Vortex Café
Desktop, Embedded and Mobile Apps with Vortex CaféDesktop, Embedded and Mobile Apps with Vortex Café
Desktop, Embedded and Mobile Apps with Vortex CaféAngelo Corsaro
 
maXbox Arduino Tutorial
maXbox Arduino TutorialmaXbox Arduino Tutorial
maXbox Arduino TutorialMax Kleiner
 
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''OdessaJS Conf
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programmingelliando dias
 

Similar to Windows 8.1 Sockets (20)

Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with php
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
 
Simplified Networking and Troubleshooting for K-12 Teachers
Simplified Networking and Troubleshooting for K-12 TeachersSimplified Networking and Troubleshooting for K-12 Teachers
Simplified Networking and Troubleshooting for K-12 Teachers
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
 
Practical Security with MQTT and Mosquitto
Practical Security with MQTT and MosquittoPractical Security with MQTT and Mosquitto
Practical Security with MQTT and Mosquitto
 
Puppet Camp Boston 2014: Keynote
Puppet Camp Boston 2014: Keynote Puppet Camp Boston 2014: Keynote
Puppet Camp Boston 2014: Keynote
 
Sockets
SocketsSockets
Sockets
 
Networking and communications security – network architecture design
Networking and communications security – network architecture designNetworking and communications security – network architecture design
Networking and communications security – network architecture design
 
FMS Administration Seminar
FMS Administration SeminarFMS Administration Seminar
FMS Administration Seminar
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
 
Network And Network Address Translation
Network And Network Address TranslationNetwork And Network Address Translation
Network And Network Address Translation
 
Optimizing windows 8 for virtual desktops - teched 2013 Jeff Stokes
Optimizing windows 8 for virtual desktops - teched 2013 Jeff StokesOptimizing windows 8 for virtual desktops - teched 2013 Jeff Stokes
Optimizing windows 8 for virtual desktops - teched 2013 Jeff Stokes
 
Desktop, Embedded and Mobile Apps with PrismTech Vortex Cafe
Desktop, Embedded and Mobile Apps with PrismTech Vortex CafeDesktop, Embedded and Mobile Apps with PrismTech Vortex Cafe
Desktop, Embedded and Mobile Apps with PrismTech Vortex Cafe
 
Desktop, Embedded and Mobile Apps with Vortex Café
Desktop, Embedded and Mobile Apps with Vortex CaféDesktop, Embedded and Mobile Apps with Vortex Café
Desktop, Embedded and Mobile Apps with Vortex Café
 
maXbox Arduino Tutorial
maXbox Arduino TutorialmaXbox Arduino Tutorial
maXbox Arduino Tutorial
 
Python networking
Python networkingPython networking
Python networking
 
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
Alexey Orlenko ''High-performance IPC and RPC for microservices and apps''
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programming
 

Recently uploaded

QMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfQMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfROWELL MARQUINA
 
Why Agile? - A handbook behind Agile Evolution
Why Agile? - A handbook behind Agile EvolutionWhy Agile? - A handbook behind Agile Evolution
Why Agile? - A handbook behind Agile EvolutionDEEPRAJ PATHAK
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Which standard is best for your content?
Which standard is best for your content?Which standard is best for your content?
Which standard is best for your content?Rustici Software
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Deliver Latency Free Customer Experience
Deliver Latency Free Customer ExperienceDeliver Latency Free Customer Experience
Deliver Latency Free Customer ExperienceOpsTree solutions
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Dynamical Context introduction word sensibility orientation
Dynamical Context introduction word sensibility orientationDynamical Context introduction word sensibility orientation
Dynamical Context introduction word sensibility orientationBuild Intuit
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 

Recently uploaded (20)

QMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfQMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdf
 
Why Agile? - A handbook behind Agile Evolution
Why Agile? - A handbook behind Agile EvolutionWhy Agile? - A handbook behind Agile Evolution
Why Agile? - A handbook behind Agile Evolution
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Which standard is best for your content?
Which standard is best for your content?Which standard is best for your content?
Which standard is best for your content?
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Deliver Latency Free Customer Experience
Deliver Latency Free Customer ExperienceDeliver Latency Free Customer Experience
Deliver Latency Free Customer Experience
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Dynamical Context introduction word sensibility orientation
Dynamical Context introduction word sensibility orientationDynamical Context introduction word sensibility orientation
Dynamical Context introduction word sensibility orientation
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 

Windows 8.1 Sockets

  • 2. Consulting/Training consulting Wintellect helps you build better software, faster, tackling the tough projects and solving the software and technology questions that help you transform your business.  Architecture, Analysis and Design  Full lifecycle software development  Debugging and Performance tuning  Database design and development training Wintellect's courses are written and taught by some of the biggest and most respected names in the Microsoft programming industry.  Learn from the best. Access the same training Microsoft’s developers enjoy  Real world knowledge and solutions on both current and cutting edge technologies  Flexibility in training options – onsite, virtual, on demand Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins – we pull out all the stops to help our customers achieve their goals through advanced software-based consulting and training solutions. who we are About Wintellect
  • 3. Consulting/Training  Sockets, Simplified  WebSockets  UDP and TCP Sockets  Proximity / NFC “Tap to Connect”  Bluetooth and Wi-Fi Direct  Recap Agenda
  • 4. Consulting/Training  Covers full WinRT API  Over 80 example projects  This presentation is based on Chapter 10  Full source online at http://winrtexamples .codeplex.com/  Book available at http://bit.ly/winrtxmpl WinRT by Example
  • 7. Consulting/Training Sockets, Simplified Stream  Length (maybe)  Position  Read  Write  Seek
  • 9. Consulting/Training  Berkeley sockets released with Unix in 1983 (owned by AT&T at the time) for “IPC” while I was writing my first Commodore 64 programs in 6502 assembly  Open licensing in 1989 (I had finally moved to IBM PC and MS-DOS)  POSIX API (Portable Operating System Interface) released in 1988  Windows Sockets API (WSA or Winsock) released in 1992 (I graduated high school and discovered the Internet in college) and later implemented for Windows  Another F Ancillary Function Driver (AFD.sys) still exists to this day Sockets: A Brief History
  • 12. Consulting/Training  A way to communicate between end points  Usually operate on streams, which are abstractions over buffers that contain bytes  But can be a datagram that has no connection  A socket connection has two distinct end points  An end point is a combination of an address and a port  End points can be hosted on the same machine, or different machines Sockets Recap
  • 13. Consulting/Training int main(void) { struct sockaddr_in stSockAddr; int Res; int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (-1 == SocketFD) { perror("cannot create socket"); exit(EXIT_FAILURE); } memset(&stSockAddr, 0, sizeof(stSockAddr)); stSockAddr.sin_family = AF_INET; stSockAddr.sin_port = htons(1100); Res = inet_pton(AF_INET, "192.168.1.1", &stSockAddr.sin_addr); (void) shutdown(SocketFD, SHUT_RDWR); close(SocketFD); return EXIT_SUCCESS; } “The Old Days” (still valid 30 yrs. later)
  • 14. Consulting/Training  Sit on top of TCP (you’ll learn more about TCP later)  Operate over ports 80/443 by default (keeps firewalls happy)  Use HTTP for the initial “handshake”  Provide full-duplex communications  WinRT implementation allows for message- based or stream-based WebSockets
  • 15. Consulting/Training GET /info HTTP/1.1 HOST: 1.2.3.4 Upgrade: websocket Connection: Upgrade Origin: http://jeremylikness.com/ HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade WebSocket Handshake Placing my call … Accepting …. Now it’s streams from here on out….
  • 16. Consulting/Training (a prime example… source code: http://bit.ly/1i5vB9p) WebSockets
  • 17. Consulting/Training  Both are communication protocols for delivering octet streams (bytes!)  UDP is fire-and-forget (connectionless)  Individual messages sent, i.e. “datagrams”  Fast, lots of questions: DNS, DHCP, SNMP  TCP is connection-oriented  TCP is stream-based  Slower, but reliable: HTTP, FTP, SMTP, Telnet UDP and TCP
  • 18. Consulting/Training this.serverSocket = new StreamSocketListener(); this.serverSocket.ConnectionReceived += this.ServerSocketConnectionReceived; await this.serverSocket.BindServiceNameAsync(ServiceName); // can both read and write messages (full-duplex) if (serverWriter == null) { serverWriter = new DataWriter(args.Socket.OutputStream); serverReader = new DataReader(args.Socket.InputStream); } Server Listens for Connections
  • 19. Consulting/Training var hostName = new HostName("localhost"); this.clientSocket = new StreamSocket(); await this.clientSocket.ConnectAsync(hostName, ServiceName); clientWriter = new DataWriter(this.clientSocket.OutputStream); clientReader = new DataReader(this.clientSocket.InputStream); // both client and server require long-running tasks to wait for // messages and send them as needed while (true) { var data = await GetStringFromReader(clientReader); // do something with the data } Client “Dials In” to Chat
  • 20. Consulting/Training (a true adventure… source code: http://bit.ly/1j77rP3) TCP Sockets
  • 21. Consulting/Training  Near Field Communications (NFC) is a standard for extremely low powered communications typically very slow and over a very small distance, between devices and/or smart tags  NFC is capable of sending small bursts of information. However, “tap to connect” is a powerful mechanism for establishing a hand-shake to open a stream over other, longer range and faster protocols like Bluetooth and Wi-Fi Direct  Windows Runtime exposes the Proximity APIs that provide a unified way to discover nearby devices and a protocol-agnostic mechanism to connect  Literally you can discover, handshake, etc. and WinRT will “hand-off” a socket that is ready to use (you won’t even know if it is over Wi-Fi Direct or Bluetooth)  Bluetooth = short wavelength wireless technology  Wi-Fi Direct = peer to peer over Wi-Fi (wireless cards without requiring a wireless access point or router) NFC and Proximity
  • 22. Consulting/Training this.proximityDevice = ProximityDevice.GetDefault(); this.proximityDevice.DeviceArrived += this.ProximityDeviceDeviceArrived; this.proximityDevice.DeviceDeparted += this.ProximityDeviceDeviceDeparted; PeerFinder.ConnectionRequested += this.PeerFinderConnectionRequested; PeerFinder.Role = PeerRole.Peer; PeerFinder.Start(); var peers = await PeerFinder.FindAllPeersAsync(); var socket = await PeerFinder.ConnectAsync(this.SelectedPeer.Information); Proximity APIs NFC device and events Peer Finder (listen and browse) Browse for peers Connect to peer
  • 23. Consulting/Training 1. Try to get Proximity Device (NFC) 2. If exists, register to enter/leave events (NFC) 3. If it supports triggers (i.e. tap) register for connection state change event (NFC) 4. Otherwise browse for peers (Wi-Fi Direct, Bluetooth) 5. When a peer is found, send a connection request 6. Peer must accept the connection request 7. In any scenario, once the connection exists you are passed a stream socket and are free to communicate Steps for Proximity
  • 25. Consulting/Training  WebSockets API for simplified WebSockets  Sockets API for TCP, UDP, Bluetooth, Wi-Fi Direct  Windows 8.1 is capable of dialing out to any address and port  As a server, most practical example is listening for Bluetooth connections  The security sandbox prevents using sockets for inter-app communications Recap
  • 26. Consulting/Training Subscribers Enjoy  Expert Instructors  Quality Content  Practical Application  All Devices Wintellect’s On-Demand Video Training Solution Individuals | Businesses | Enterprise Organizations WintellectNOW.com Authors Enjoy  Royalty Income  Personal Branding  Free Library Access  Cross-Sell Opportunities Try It Free! Use Promo Code: LIKNESS-13