Upload
nicholas-valbusa
View
980
Download
0
Embed Size (px)
DESCRIPTION
"Bonjour" è ben più di un formale saluto in francese. :) Molti programmatori lo usano durante il proprio lavoro ma pochissimi lo conoscono veramente. Non stiamo ovviamente parlando della lingua francese, ma di "Bonjour", il protocollo di comunicazione che da anni viene utilizzato sui sistemi operativi iOS, OSX assieme ad altre piattaforme, tra cui Android. Durante questo talk esploreremo i suoi vantaggi principali, per poi imparare a utilizzarlo attraverso un caso reale: verrà illustrato lo sviluppo di un'applicazione nativa per iPad che metta in comunicazione diversi device all'interno della medesima rete, creando una chat ed un servizio di ScreenCast.
Citation preview
Nicholas Valbusa - @squallstarIntesys Web Agency
APPLE BONJOUR,LET’S TALK!
Thursday, May 24, 12
Thursday, May 24, 12
Few words about me
Thursday, May 24, 12
Nicholas Valbusa@squallstar
Few words about me
Thursday, May 24, 12
Nicholas Valbusa@squallstar
Few words about me
Web Developer since 2004
Thursday, May 24, 12
Nicholas Valbusa@squallstar
Few words about me
Mobile Developer since 2010
Web Developer since 2004
Thursday, May 24, 12
Nicholas Valbusa@squallstar
Few words about me
Mobile Developer since 2010WHYMCA 2011: Webkit meets Native development
Web Developer since 2004
Thursday, May 24, 12
Thursday, May 24, 12
Intesys è una Web Agency Innovativa nata nel 1995 a Verona
Thursday, May 24, 12
Intesys è una Web Agency Innovativa nata nel 1995 a Verona
Un team di 90 specialisti divisi in 4 aree
Thursday, May 24, 12
Intesys è una Web Agency Innovativa nata nel 1995 a Verona
Un team di 90 specialisti divisi in 4 aree
Thursday, May 24, 12
We’ll talk about
Thursday, May 24, 12
We’ll talk about
Thursday, May 24, 12
We’ll talk about
Thursday, May 24, 12
• TCP/IP
We’ll talk about
Thursday, May 24, 12
• TCP/IP• Apple Bonjour, uPNP
We’ll talk about
Thursday, May 24, 12
• TCP/IP• Apple Bonjour, uPNP• Socket, Stream, Buffers
We’ll talk about
Thursday, May 24, 12
• TCP/IP• Apple Bonjour, uPNP• Socket, Stream, Buffers• Create and publish a server
We’ll talk about
Thursday, May 24, 12
• TCP/IP• Apple Bonjour, uPNP• Socket, Stream, Buffers• Create and publish a server• Join a server
We’ll talk about
Thursday, May 24, 12
• TCP/IP• Apple Bonjour, uPNP• Socket, Stream, Buffers• Create and publish a server• Join a server• Network messages
We’ll talk about
Thursday, May 24, 12
• TCP/IP• Apple Bonjour, uPNP• Socket, Stream, Buffers• Create and publish a server• Join a server• Network messages• Other...
We’ll talk about
Thursday, May 24, 12
We’ll see
Thursday, May 24, 12
We’ll see
• A screencast native application
Thursday, May 24, 12
We’ll see
• A screencast native application• Something like chats
Thursday, May 24, 12
We’ll see
• A screencast native application• Something like chats• Where server can send images and other things
Thursday, May 24, 12
We’ll see
• A screencast native application• Something like chats• Where server can send images and other things
Follow the talk from your iPad using the same app that we’re going to make
iCast
Thursday, May 24, 12
iCast
Thursday, May 24, 12
iCast
Thursday, May 24, 12
iCast
Thursday, May 24, 12
Thursday, May 24, 12
“Once upon a time”
Thursday, May 24, 12
“Once upon a time”
Apple Talk
Thursday, May 24, 12
“Once upon a time”
• Protocollo usato nelle reti Macintosh
Apple Talk
Thursday, May 24, 12
“Once upon a time”
• Protocollo usato nelle reti Macintosh• Condivisione di file e stampanti
Apple Talk
Thursday, May 24, 12
“Once upon a time”
• Protocollo usato nelle reti Macintosh• Condivisione di file e stampanti• Uno dei primi sistemi plug-n-play
Apple Talk
Thursday, May 24, 12
Thursday, May 24, 12
“things changes”
Thursday, May 24, 12
TCP/IP
“things changes”
Thursday, May 24, 12
TCP/IP
• Negli anni novanta, con la diffusione del TCP/IP Apple dismesse AppleTalk
“things changes”
Thursday, May 24, 12
TCP/IP
• Negli anni novanta, con la diffusione del TCP/IP Apple dismesse AppleTalk• Finalmente i Mac potevano connettersi con
altri sistemi operativi
“things changes”
Thursday, May 24, 12
Thursday, May 24, 12
ZeroconfDHCP DNS
Thursday, May 24, 12
ZeroconfDHCP DNS
“A set of techniques that automatically creates a usable IP network without manual operator intervention”
Thursday, May 24, 12
Thursday, May 24, 12
Bonjour
Thursday, May 24, 12
Bonjour
L’implementazione Appledi “Zero configuration network”
Thursday, May 24, 12
Bonjour
L’implementazione Appledi “Zero configuration network”
“It just works”
Thursday, May 24, 12
Bonjour
• mDNS + DNS Service discovery
L’implementazione Appledi “Zero configuration network”
“It just works”
Thursday, May 24, 12
Bonjour
• mDNS + DNS Service discovery• Address assignment
L’implementazione Appledi “Zero configuration network”
“It just works”
Thursday, May 24, 12
Bonjour
• mDNS + DNS Service discovery• Address assignment• Name resolution
L’implementazione Appledi “Zero configuration network”
“It just works”
Thursday, May 24, 12
Bonjour
Thursday, May 24, 12
• Built-in con OSX e iOS.
Bonjour
Thursday, May 24, 12
• Built-in con OSX e iOS.• Installabile su Windows
Bonjour
Thursday, May 24, 12
• Built-in con OSX e iOS.• Installabile su Windows• Incluso in Safari e iTunes.
Bonjour
Thursday, May 24, 12
• Built-in con OSX e iOS.• Installabile su Windows• Incluso in Safari e iTunes.• Incluso nella Creative Suite 3 di Adobe
Bonjour
Thursday, May 24, 12
Thursday, May 24, 12
Who uses it
Thursday, May 24, 12
Who uses it• iTunes finds shared music
Thursday, May 24, 12
Who uses it• iTunes finds shared music• iPhotos finds shared photos
Thursday, May 24, 12
Who uses it• iTunes finds shared music• iPhotos finds shared photos• iChat, Skype, Adium
Thursday, May 24, 12
Who uses it• iTunes finds shared music• iPhotos finds shared photos• iChat, Skype, Adium• Adobe Creative Suite 3+
Thursday, May 24, 12
Who uses it• iTunes finds shared music• iPhotos finds shared photos• iChat, Skype, Adium• Adobe Creative Suite 3+• Things, Omnifocus
Thursday, May 24, 12
Who uses it• iTunes finds shared music• iPhotos finds shared photos• iChat, Skype, Adium• Adobe Creative Suite 3+• Things, Omnifocus• Cyberduck, Coda, SubEthaEdit
Thursday, May 24, 12
Who uses it• iTunes finds shared music• iPhotos finds shared photos• iChat, Skype, Adium• Adobe Creative Suite 3+• Things, Omnifocus• Cyberduck, Coda, SubEthaEdit• PostgreSQL
Thursday, May 24, 12
Who uses it• iTunes finds shared music• iPhotos finds shared photos• iChat, Skype, Adium• Adobe Creative Suite 3+• Things, Omnifocus• Cyberduck, Coda, SubEthaEdit• PostgreSQL• All uPNP-enabled devices
Thursday, May 24, 12
Thursday, May 24, 12
Who can also use it
Thursday, May 24, 12
Who can also use it
Thursday, May 24, 12
Using “jmDNS”, a Java implementationof multi-cast DNS for LAN service registration/discovery.
Who can also use it
Thursday, May 24, 12
Thursday, May 24, 12
uPNPUniversal plug-n-play
Thursday, May 24, 12
uPNP
• It’s just another implementation of Zeroconf
Universal plug-n-play
Thursday, May 24, 12
uPNP
• It’s just another implementation of Zeroconf• Media servers, Consoles, DLNA servers...
Universal plug-n-play
Thursday, May 24, 12
uPNP
• It’s just another implementation of Zeroconf• Media servers, Consoles, DLNA servers...• No authentication
Universal plug-n-play
Thursday, May 24, 12
uPNP
• It’s just another implementation of Zeroconf• Media servers, Consoles, DLNA servers...• No authentication• No mDNS
Universal plug-n-play
Thursday, May 24, 12
Thursday, May 24, 12
Bonjour: Service Publication
Thursday, May 24, 12
Bonjour: Service Publication
Thursday, May 24, 12
Thursday, May 24, 12
Bonjour: Service Publication
Thursday, May 24, 12
Bonjour: Service Publication
Thursday, May 24, 12
Thursday, May 24, 12
Bonjour: Query for services
Thursday, May 24, 12
Bonjour: Query for services
Thursday, May 24, 12
Thursday, May 24, 12
Bonjour: Connect
Thursday, May 24, 12
Bonjour: Connect
Thursday, May 24, 12
Thursday, May 24, 12
Sockets vs Streams
Thursday, May 24, 12
Sockets vs Streams
• Socket: unique communication endpoint on the network
Thursday, May 24, 12
Sockets vs Streams
• Socket: unique communication endpoint on the network
• Stream: one-way channel through which data is transmitted serially
Thursday, May 24, 12
Thursday, May 24, 12
We will use
Thursday, May 24, 12
We will use
• Stream sockets that are paired up to allow our app to send data over network using TCP/IP
Thursday, May 24, 12
We will use
• Stream sockets that are paired up to allow our app to send data over network using TCP/IP
• Asynchronous, non-blocking operations
Thursday, May 24, 12
Thursday, May 24, 12
3 Networking Classes
Thursday, May 24, 12
3 Networking Classes
Server class:
Thursday, May 24, 12
3 Networking Classes
• Creates a server
Server class:
Thursday, May 24, 12
3 Networking Classes
• Creates a server• Announces the server via Bonjour
Server class:
Thursday, May 24, 12
3 Networking Classes
• Creates a server• Announces the server via Bonjour
Server class:
Connection class:
Thursday, May 24, 12
3 Networking Classes
• Creates a server• Announces the server via Bonjour
Server class:
• Resolves Bonjour Services
Connection class:
Thursday, May 24, 12
3 Networking Classes
• Creates a server• Announces the server via Bonjour
Server class:
• Resolves Bonjour Services• Establishes connections to other servers
Connection class:
Thursday, May 24, 12
3 Networking Classes
• Creates a server• Announces the server via Bonjour
Server class:
• Resolves Bonjour Services• Establishes connections to other servers• Exchanges data via socket streams
Connection class:
Thursday, May 24, 12
3 Networking Classes
• Creates a server• Announces the server via Bonjour
Server class:
• Resolves Bonjour Services• Establishes connections to other servers• Exchanges data via socket streams
Connection class:
Server Browser class:
Thursday, May 24, 12
3 Networking Classes
• Creates a server• Announces the server via Bonjour
Server class:
• Resolves Bonjour Services• Establishes connections to other servers• Exchanges data via socket streams
Connection class:
• Browses for other servers via BonjourServer Browser class:
Thursday, May 24, 12
Thursday, May 24, 12
Application layers
Thursday, May 24, 12
Application layers
Thursday, May 24, 12
Application layers
Thursday, May 24, 12
Application layers
Thursday, May 24, 12
Thursday, May 24, 12
Down the Connection class
Thursday, May 24, 12
Down the Connection class
2 stream sockets (one for writing, one for reading)2 data buffers (one for each socket stream)
Thursday, May 24, 12
Thursday, May 24, 12
Network messages
Thursday, May 24, 12
Network messages
How do we separate network messages from one another?
Thursday, May 24, 12
Network messages
How do we separate network messages from one another?
3 different ways:
Thursday, May 24, 12
Network messages
How do we separate network messages from one another?
1) Make all messages have the same length
3 different ways:
Thursday, May 24, 12
Network messages
How do we separate network messages from one another?
1) Make all messages have the same length2) Append a marker to each message
3 different ways:
Thursday, May 24, 12
Network messages
How do we separate network messages from one another?
1) Make all messages have the same length2) Append a marker to each message
3) Send some kind of header with some info about how long the message is
3 different ways:
Thursday, May 24, 12
Network messages
How do we separate network messages from one another?
1) Make all messages have the same length2) Append a marker to each message
3) Send some kind of header with some info about how long the message is
3 different ways:
Thursday, May 24, 12
Thursday, May 24, 12
3) Send some kind of header...
Thursday, May 24, 12
Writing messages
3) Send some kind of header...
Thursday, May 24, 12
Writing messages
• Convert an object into a byte array and measure its length
3) Send some kind of header...
Thursday, May 24, 12
Writing messages
• Convert an object into a byte array and measure its length
• Write the integer (4 bytes) that represents the length of our byte array to the stream
3) Send some kind of header...
Thursday, May 24, 12
Writing messages
• Convert an object into a byte array and measure its length
• Write the integer (4 bytes) that represents the length of our byte array to the stream
• Write the actual byte array to the stream
3) Send some kind of header...
Thursday, May 24, 12
Reading messages
Thursday, May 24, 12
Reading messages
• Read first 4 bytes and interpret those as an integer called “x”
Thursday, May 24, 12
Reading messages
• Read first 4 bytes and interpret those as an integer called “x”
• Read “x” number of bytes. (stop when enough data has been received)
Thursday, May 24, 12
Reading messages
• Read first 4 bytes and interpret those as an integer called “x”
• Read “x” number of bytes. (stop when enough data has been received)
• Turn received sequence of bytes back into an object.
Thursday, May 24, 12
Thursday, May 24, 12
It’s time!
Thursday, May 24, 12
Thursday, May 24, 12
Frameworks
Thursday, May 24, 12
• Low level: BSD socket lib
Frameworks
Thursday, May 24, 12
• Low level: BSD socket lib
Frameworks
Thursday, May 24, 12
• Low level: BSD socket lib
Frameworks
• High level: CFNetwork
Thursday, May 24, 12
• Low level: BSD socket lib
Frameworks
• High level: CFNetwork
• Bonjour iOS API: NSNetServices, CFNetServices
Thursday, May 24, 12
Thursday, May 24, 12
Creating a server
Thursday, May 24, 12
Creating a server
We first create a stream socket that will listen for
connections
Thursday, May 24, 12
Creating a server
We first create a stream socket that will listen for
connections
CFSocketRef listeningSocket;
Thursday, May 24, 12
Creating a server
We first create a stream socket that will listen for
connections
CFSocketRef listeningSocket;
using port number 0
Thursday, May 24, 12
Creating a server
We first create a stream socket that will listen for
connections
CFSocketRef listeningSocket;
using port number 0
zero???? O_o
Thursday, May 24, 12
Thursday, May 24, 12
Let’s publish the service
Thursday, May 24, 12
Let’s publish the service
Thursday, May 24, 12
Thursday, May 24, 12
Services/Servers Browser
Thursday, May 24, 12
Services/Servers Browser
Thursday, May 24, 12
Thursday, May 24, 12
Found!
Thursday, May 24, 12
Found!
Thursday, May 24, 12
Thursday, May 24, 12
Displaying servers list
Thursday, May 24, 12
Displaying servers list
Thursday, May 24, 12
Thursday, May 24, 12
Please let me join
Thursday, May 24, 12
Please let me join
Thursday, May 24, 12
Please let me join
Thursday, May 24, 12
Please let me join
Thursday, May 24, 12
Please let me join
Thursday, May 24, 12
Thursday, May 24, 12
The server receives the “request”
Thursday, May 24, 12
The server receives the “request”
Thursday, May 24, 12
Thursday, May 24, 12
The server welcomes you
Thursday, May 24, 12
The server welcomes you
Thursday, May 24, 12
The server welcomes you
Thursday, May 24, 12
Thursday, May 24, 12
The client receives the stream
Thursday, May 24, 12
The client receives the stream
Thursday, May 24, 12
Thursday, May 24, 12
Recap
Thursday, May 24, 12
Recap• Apple Talk, TCP/IP
Thursday, May 24, 12
Recap• Apple Talk, TCP/IP• Bonjour flow cycle, uPNP
Thursday, May 24, 12
Recap• Apple Talk, TCP/IP• Bonjour flow cycle, uPNP• Application layers, Socket, Stream, Buffers
Thursday, May 24, 12
Recap• Apple Talk, TCP/IP• Bonjour flow cycle, uPNP• Application layers, Socket, Stream, Buffers• Write/Read Network messages
Thursday, May 24, 12
Recap• Apple Talk, TCP/IP• Bonjour flow cycle, uPNP• Application layers, Socket, Stream, Buffers• Write/Read Network messages• Create and publish a server
Thursday, May 24, 12
Recap• Apple Talk, TCP/IP• Bonjour flow cycle, uPNP• Application layers, Socket, Stream, Buffers• Write/Read Network messages• Create and publish a server• Join a server
Thursday, May 24, 12
Recap• Apple Talk, TCP/IP• Bonjour flow cycle, uPNP• Application layers, Socket, Stream, Buffers• Write/Read Network messages• Create and publish a server• Join a server• Interaction between the client and the server
Thursday, May 24, 12
Recap• Apple Talk, TCP/IP• Bonjour flow cycle, uPNP• Application layers, Socket, Stream, Buffers• Write/Read Network messages• Create and publish a server• Join a server• Interaction between the client and the server
• One more thing: server broadcasts messages to connected clients
Thursday, May 24, 12
Thursday, May 24, 12
Any questions?Thank you.
Nicholas Valbusa@squallstar
Intesys - @Intesys_IT - www.intesys.it
Thursday, May 24, 12