itcamp2012-real-time-web-web-sockets-windows 8- florin-cardasim

28
itcampro @ itcamp12 # Premium conference on Microsoft technologies Architectur e & Best Practices ITCamp 2012 sponsors

Upload: florin-cardasim

Post on 12-May-2015

1.668 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

ITCamp 2012 sponsors

Page 2: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Real-time web and Web Sockets in Windows 8

Florin Cardașim, Endava, twitter/@cardasim

Page 3: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

Real-time web

Comet/long polling

SSE, WebSockets

WebSockets in ASP.NET and WCF

Q&A

Agenda

Page 4: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

Real-Time Web

• Monitoring/dashboards• Sensor/RFID Tracking• Social networking, Instant messaging• Collaboration tools (Google Docs)• Online gaming (Quake2 in the

browser??!!)• …

Page 5: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

Implementing Real-Time Web

• Flash/silverlight/javafx• Ajax polling• Comet/long polling/http streaming …• … other DoS techniques

• Server-sent events• Web sockets

Page 6: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

Pollingconnectno messageconnectno message

eventconnectevent

Browser Server

connectno message

connectno message eventconnectevent

Page 7: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best PracticesPolling

• No real-time user experience• Wasted bandwidth, most requests

return no data• Frequent polling determine high

server loads

Page 8: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

Comet/Long Polling

connect

eventevent

Browser Server

event

wait

connectwait

eventconnect

wait

Page 9: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

Comet/Long Polling

• Real-time user experience

• High pressure on server memory, bandwidth, threads/processes

• DEMO

Page 10: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

Html5 Server-Sent Events

open event stream

eventevent

Browser Server

eventO

pen

HTTP co

nn

ectio

n

event

eventevent

<EventSource>

onmessageonmessageonmessage

Page 11: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best PracticesHtml5 Server-Sent Events

• Simulates a server push channel over HTTP

• Unidirectional, from server to browser• Standardizes some form of Comet/HTTP

streaming

• New html tag: <EventSource>• New mime type: text/event-stream

Page 12: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best PracticesHtml5 WebSocket

Client/Browser

ServerGET /text HTTP/1.1Host: www.websocket.orgUpgrade: WebSocket Connection: Upgrade ...

HTTP/1.1 101 Switching ProtocolsUpgrade: WebSocketConnection: Upgrade ...

TCP comm channelFull duplex, bidirectional

Page 13: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best PracticesHtml5 WebSocket

• Full duplex, bidirectional• Single TCP socket• Standard ports: http/80, https/443• In & outside of browser• Bandwidth savings, enhanced

scalability

Page 14: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best PracticesWebSocket vs Polling Bandwidth

http://websocket.org/quantum.html

Page 15: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

WebSocket – The Protocol

OpCode (4 bit)

Meaning/frame type

0 Continuation

1 Text (UTF-8)

2 Binary

3-7 Reserved for further non-control frames

8 Connection Close

9 Ping

10 Pong

11-15 Reserved for further non-control frames

Page 16: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

WebSocket – The Java Script API

Page 17: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best PracticesBrowser Support

Page 18: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

Server Side Support

• Socket.IO (node.js)• Atmosphere, Jetty (Java)• Ruby/EventMachine• Python/Twisted• Windows 8, IIS 8, ASP.NET-WCF 4.5• … others

Page 19: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best PracticesWebSockets in Windows 8

http.sys

IIS (iiswsock.dll)

ASP.NET HTTP Pipeline

System.Net.WebSockets

HttpListener

WCF WebSocket transport

WCF high level abstractions

Your code!

ASP.NET high level abstractions

Page 20: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

WebSockets in Windows 8

• DEMO• IE 10• Windows 8, IIS 8• ASP.NET 4.5• WCF 4.5

Page 21: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best PracticesWebSockets in ASP.NET

Developer “agrees” to upgrade to a WebSocket connection

HttpContext.Current.AcceptWebSocketRequest(Func<AspNetWebSocketContext,Task> myWebSocketApp,AspNetWebSocketOptions optionalSetupInfo

);

Asynchronously receive and send messagespublic async Task MyWebSocketApp(AspNetWebSocketContext context){

var socket = context.WebSocket;…var input = await socket.ReceiveAsync(buffer);…await socket.SendAsync(outputBuffer,…params…);

}

Page 22: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

WebSockets in WCF

• WebSocket transport for WCF• Traditional WCF running over

WebSocket connections

<bindings>

<netHttpBinding><binding name="websocketBinding"> <webSocketSettings connectionMode="Required"

pingFrequency="00:01:00" /></binding>

</netHttpBinding></bindings>

Page 23: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

Concerns – Network Topology

• NAT, Firewall– NOT an issue, standard ports: http/80, https/443

• Proxy (forward, reverse, transparent etc)– It depends, but generally an issue– CONNECT (tunnel/SSL)

• Load Balancer– TCP (Layer-4) – no issue– HTTP (Layer-7) – may require explicit configuration

Page 24: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

Concerns – Adoption

• Use frameworks:–Socket.IO

(node.js)–Atmosphere

(java)–SignalR (.net)

Page 25: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

References

• http://www.websocket.org• http://www.kaazing.me• http://www.buildwindows.com• http://ww.infoq.com/websocket• http://socket.io

Page 26: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Architecture & Best Practices

Other WebSockets sessions @ITCamp

• Building modern web sites with ASP .Net Web API, WebSockets and SignalR– 14:45– Alessandro Pilotti

Page 27: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

Q & A

How will WebSocket impact the existing WEB programming?

Page 28: ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim

itcampro@ itcamp12# Premium conference on Microsoft technologies

I’d love to hear you feedback – please fill the

evaluation forms

Thank you!

Florin Cardașim, Endava, twitter/@cardasim