WebSockets [intro].

Slides:



Advertisements
Similar presentations
What’s New in Windows Communication Foundation in Microsoft.NET 4.5 Daniel Roth Senior Program Manager Microsoft Corporation DEV326.
Advertisements

Real-time Collaborative Scientific WebGL Visualization with WebSocket Julien Jomier & Charles Marion Web3D Conference 2012.
HTML5 Applications with ASP.NET Web Forms Stephen Walther Superexpert.com
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 1.
Rensselaer Polytechnic Institute CSCI-4220 – Network Programming David Goldschmidt, Ph.D.
Martin Kruliš by Martin Kruliš (v1.0)1.
9. AJAX & RIA. 2 Motto: O! call back yesterday, bid time return. — William Shakespeare.
1/ November 2008 / EDS Internal Web Push Technology Dušan Chromý SOA Integration Consulting Reverse Ajax/Comet Explained.
Popular Web client and server programs This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License. Skills: none IT.
CSCI 4550/8556 Computer Networks Comer, Chapter 3: Network Programming and Applications.
Web architecture Dr Jim Briggs Web architecture.
The World Wide Web and the Internet Dr Jim Briggs 1WUCM1.
SignalR Real Time with SignalR Jared Rhodes Senior Consultant Magenic.
Reverse AJAX and HTML5 Based Clients for Embedded Control and Monitoring Systems C Robson, C Bohm, Stockholm University or "HTML5, why should we care?"
Boris Tshibangu. What is a proxy server? A proxy server is a server (a computer system or an application) that acts as an intermediary for requests from.
It’s World Wide! I NTRODUCTION TO T HE WEB 1 Photo courtesy:
WEB DESIGN SOME FOUNDATIONS. SO WHAT IS THIS INTERNET.
© 2010 UEI, Inc. All Rights Reserved UEIPAC HMI.
Lightning Talk Fred Rodriguez Aakash Juneja CPSC 473 March 16, 2012.
Written by Matthew Shelley for Professor Wei Shi.
Josh
Rensselaer Polytechnic Institute CSCI-4220 – Network Programming David Goldschmidt, Ph.D.
Ajax Basics The XMLHttpRequest Object. Ajax is…. Ajax is not…. Ajax is not a programming language. Ajax is not a programming language. Ajax is a methodology.
Ajax Application Errors Developer Oversight and Tracking Errors Presented by Eric Pascarello.
1 What Can HTML5 WebSocket Do For You? Sidda Eraiah Director of Management Services Kaazing Corporation.
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
AJAX and Java ISYS 350. AJAX Asynchronous JavaScript and XML: – Related technologies: JavaScript, Document Object Model, XML, server-side script such.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
 You’re already a Web Site Dev  You’re interested in more simply making your web sites more responsive  If you’re not already hosting sites in.
WEB WORKERS 1 Amitesh Madhur (Exceptional Performance, Bangalore)
Web Engineering we define Web Engineering as follows: 1) Web Engineering is the application of systematic and proven approaches (concepts, methods, techniques,
MediMizer User Group  Users want an iPad application  Users want a web application  IT wants a no-installation client  Can be used anywhere.
1 82 nd IETF meeting NETCONF over WebSocket ( ) Tomoyuki Iijima, (Hitachi) Hiroyasu Kimura,
NETWORK HARDWARE AND SOFTWARE MR ROSS UNIT 3 IT APPLICATIONS.
Web Design (1) Terminology. Coding ‘languages’ (1) HTML - Hypertext Markup Language - describes the content of a web page CSS - Cascading Style Sheets.
HTML5 Websockets Norman White Websockets The HTTP protocol is not designed for a continuous connection between the client and the server, but rather.
Progressive .NET Tutorials, July 3rd, London, UK
Server - Client Communication Getting data from server.

Zz SOCKET.IO going real time with Arnout Kazemier
Jan 2001C.Watters1 World Wide Web and E-Commerce Client Side Processing.
Socket Programming.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Using WebSockets in Web apps Presenter: Shahzad Badar.
Node.Js 1. 2 Contents About Node.Js Web requirement latest trends Introduction Simple web server creation in Node.Js Dynamic Web pages Dynamic web page.
JavaScript and Ajax (Internet Background) Week 1 Web site:
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
JavaScript, Sixth Edition Chapter 11 Updating Web Pages with Ajax.
Keith Telle Lead Software Engineer Bit Wizards Behind the Magic: SignalR Demystified.
Research of Web Real-Time Communication Based on WebSocket
How to Give Your Sencha App
WebSockets: TCP in Javascript
CS5220 Advanced Topics in Web Programming Introduction to WebSocket
Advanced Communication in Web Technologies
Building real-time web apps with WebSockets using IIS, ASP.NET and WCF
WebSocket: Full-Duplex Solution for the Web
Building real-time web apps with HTML5 WebSockets
03 | Building a Backend with Socket.IO and Mongo
WebSocket 101 Shuai Zhao.
Introduction to HTML5 and WebSockets.
Web Socket Protocol.
Chengyu Sun California State University, Los Angeles
Web Socket Server (using node.js)
JavaScript & jQuery AJAX.
Secure Web Programming
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Lecture 14: JSON and Web SERVICES
Part II Application Layer.
Presentation transcript:

WebSockets [intro]

WebSockets? full-duplex TCP-based persistent connection message-oriented cross-origin standardized protocol JavaScript API

WebSockets in action http://wordsquared.com/ http://paintwith.me/ http://www.youtube.com/watch?v=64TcBiqmVko&feature=player_embedded …and more!

Why WebSockets? HTTP is half-duplex HTTP has too much overhead Ajax doesn’t help Comet doesn’t help

WebSocket uses Real-time updates (sports, finance) Games Collaboration & Education Feeds & rich communication Location-based services Services based on real-time APIs User Monitoring & Logging

WebSocket protocol GET /chat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Origin: http://example.com Sec-WebSocket-Protocol: chat, superchat Sec-WebSocket-Version: 13 HTTP Client HTTP Server HTTP GET Upgrade request

WebSocket protocol HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= Sec-WebSocket-Protocol: chat HTTP Client HTTP Server HTTP 101 Switching Protocol response

Using WebSockets Server-side: Node.js WebSocket-Node Socket.IO Engine.IO C#/.NET (IIS 8 ASP.NET 4.5) XSockets.NET Fleck Java Atmosphere Ruby EM-WebSocket

WebSocket API browser support Google Chrome 16 Safari 6 Opera 12.10 Internet Explorer 10 Firefox 11

WebSocket API WebSocket WebSocket( in DOMString url, in optional DOMString protocols ); in optional DOMString[] protocols

WebSocket API Parse URL or throw SYNTAX_ERR If port is blocked, throw SECURITY_ERR Check sub-protocol Get origin from <script> Return WebSocket object Establish a socket connection

WebSocket API Status Methods readyState onopen onmessage onclose ≤123, LOL readyState CONNECTING ( = 0 ) OPEN ( = 1 ) CLOSE ( = 2 ) CLOSING onopen onmessage onclose onerror close(code, reason) send(data) String ArrayBuffer Blob https://developer.mozilla.org/en-US/docs/WebSockets/WebSockets_reference/CloseEvent#Status_codes

WebSocket API var socket = new WebSocket('ws://www.example.com/socketserver', 'protocolOne'); socket.onopen = function() { socket.send('hey'); } socket.onmessage = function(event) { var msg = JSON.parse(event.data);

WebSockets Demo Server Tablet Desktop mobile.html HTTP server deviceorientation WS server desktop.html Desktop

Binary data in JS [oh why] WebGL Files XHR2 WebSockets DataView Typed arrays Blobs Clamped arrays

Binary data in JS [is great] = 1 byte Binary data in JS [is great] var buffer = new ArrayBuffer(16) 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f var dv = new DataView(buffer, 8, 4) 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f dv.setUint16(2, 0x1337) { 13 37 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f DataView

Binary data in JS [is great] = 1 byte Binary data in JS [is great] dv.getInt8(2) -> 0x13 13 37 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f Int8, Uint8: Int16, Uint16: Int32, Uint32, Float32: Float64: x4 x2 x8

Binary data in JS [is great] = 1 byte Binary data in JS [is great] … 13 37 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f var arr = new Int32Array(buffer) 13 37 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f [0] [1] [2] [3] arr[2] ?

WAT

Binary data in JS [is great?..] = 1 byte Binary data in JS [is great?..] var arr = new Int32Array(buffer) 13 37 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f [0] [1] [2] [3] 13 37 0x08 0x09 0x0a 0x0b LSB MSB dv.setUint16(2, 0x1337, true) 0x37130000

Blobs Blob Blob( [optional] Array parts, [optional] BlobPropertyBag properties ); BlobBuilder Blob slice( optional long long start, optional long long end, optional DOMString contentType };

Binary data over WS …just send it already! opcode meaning Continuation Frame 1 Text Frame 2 Binary Frame 8 Connection Close Frame 9 Ping Frame 10 Pong Frame socket.binaryType = “arraybuffer” | “blob”

The WebSocket Challenge wsc.jit.su ArrayBuffer JSON Danger { msg:”challenge_accepted”, name: “Socketeers” } { msg: “auth”, auth_token: “6f7sd8s78”} Task1 request: { msg: “task_one”, auth_token: “6f7sd8s78”} Task1 server response: { msg: “compute”, operator:”+/-/*”, operands:[4,5]} Task1 send result: { msg: “task_one_result”, result: 9, auth_token: “6f7sd8s78” } Task2 request: { msg: ???, auth_token: “6f7sd8s78” } Task2 server response: {msg: “binary_sum”, bits: 8/16 } and ArrayBuffer (16 bytes) Convert to an unsigned typed array according to the `bits` field Task2 send result: { msg: “task_two_result”, result: 0, auth_token: “6f7sd8s78” } Check message type with typeof evt.data == “string”

The End [you are awesome]