Web Sockets Eyal Vardi CEO E4D Solutions LTD Microsoft MVP Visual C# blog: www.eVardi.com
Agenda           Type of Communications           Web Sockets API’s© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-3...
Type of Communications© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Periodic polling        Polling interval         Poll from time to time using Ajax         Delay in communications due to ...
Long polling         Poll but don’t respond untill there’s data         Poll again after data received or after the connec...
Forever Frame                                                                                 HTTP/1.1 200 OK             ...
WebSockets© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
What is WebSockets?           WebSocket is a web technology providing for            bi-directional, full-duplex communic...
WebSocket Protocol Handshake           To establish a WebSocket connection, the client            sends a WebSocket hands...
WebSocket Protocol Handshake           WebSocket data frames can be sent back and            forth between the client and...
HTML5 WebSocket API       var myWebSocket                = new WebSocket("ws://www.websockets.org");       myWebSocket.ono...
Web Socket Echo            (http://www.websocket.org/echo.html)© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Em...
Upcoming SlideShare
Loading in...5
×

HTML 5 - Web Sockets

851

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
851
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

HTML 5 - Web Sockets

  1. 1. Web Sockets Eyal Vardi CEO E4D Solutions LTD Microsoft MVP Visual C# blog: www.eVardi.com
  2. 2. Agenda  Type of Communications  Web Sockets API’s© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  3. 3. Type of Communications© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  4. 4. Periodic polling Polling interval Poll from time to time using Ajax Delay in communications due to polling interval Wastes bandwidth & latency © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  5. 5. Long polling Poll but don’t respond untill there’s data Poll again after data received or after the connection times out Consumes server threads & connection resources © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  6. 6. Forever Frame HTTP/1.1 200 OK Content-Type: text/plain Transfer-Encoding: chunked <script>eval("... ")</script>0 <script>eval("... ")</script>0 Server tells client that response is chuncked Client keeps connection open untill server closes it Server pushes data to the client followed by 0 Consumes server threads© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  7. 7. WebSockets© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  8. 8. What is WebSockets?  WebSocket is a web technology providing for bi-directional, full-duplex communications channels over a single TCP connection.  the communications are done over the regular TCP port number 80 or 443.  ws:// and wss:// prefix to indicate a WebSocket and a WebSocket Secure connection, respectively.© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  9. 9. WebSocket Protocol Handshake  To establish a WebSocket connection, the client sends a WebSocket handshake request, and the server sends a WebSocket handshake response. GET /mychat HTTP/1.1 Client Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw== Sec-WebSocket-Protocol: chat Sec-WebSocket-Version: 13 Origin: http://example.com HTTP/1.1 101 Switching Protocols Server Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk= Sec-WebSocket-Protocol: chat© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  10. 10. WebSocket Protocol Handshake  WebSocket data frames can be sent back and forth between the client and the server in full- duplex mode.  Both text and binary frames can be sent in either direction at the same time.  The data is minimally framed with just two bytes. In the case of text frames, each frame starts with a 0x00 byte, ends with a 0xFF byte, and contains UTF-8 data in between.  WebSocket text frames use a terminator, while binary frames use a length prefix.© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  11. 11. HTML5 WebSocket API var myWebSocket = new WebSocket("ws://www.websockets.org"); myWebSocket.onopen = function(evt) { alert("Connection open ..."); }; myWebSocket.onmessage = function(evt) { alert("Received Message: " + evt.data); }; myWebSocket.onclose = function(evt) { alert("Connection closed."); } myWebSocket.send("Hello WebSockets!"); myWebSocket.close();© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  12. 12. Web Socket Echo (http://www.websocket.org/echo.html)© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il

×