Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5...
Transcript of Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5...
![Page 1: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/1.jpg)
Programming WebSockets
Sean SullivanPortland Java User Group
April 20 2010
![Page 2: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/2.jpg)
![Page 3: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/3.jpg)
Agenda
• WebSockets overview
• Demo
• WebSocket programming
![Page 4: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/4.jpg)
![Page 5: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/5.jpg)
![Page 6: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/6.jpg)
Push technologies
• Flash sockets
• Silverlight duplex services
• Comet
• WebSockets
![Page 7: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/7.jpg)
![Page 8: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/8.jpg)
WebSockets
a technology that enables bidirectional communication between web browsers and server-side processes
![Page 9: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/9.jpg)
WebSockets
• Network protocol
• JavaScript API
![Page 10: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/10.jpg)
![Page 11: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/11.jpg)
![Page 12: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/12.jpg)
Demo
![Page 13: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/13.jpg)
![Page 14: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/14.jpg)
![Page 15: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/15.jpg)
![Page 16: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/16.jpg)
![Page 17: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/17.jpg)
Browser support
• Google Chrome 4.0.249.0 and higher
• WebKit nightly builds
• Firefox: TBD
• Internet Explorer 9: TBD
![Page 18: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/18.jpg)
WebSockets and HTML5
“At last week's telecon, while discussing ISSUE-64, it was proposed that we declare WebSocket (both API and protocol) out of scope for HTML5. Since the API and protocol have been in separate specs for some time, this would have no immediate material effect. However, it would prevent us from putting WebSocket back in the main HTML5 spec in the future, unless new information came to light which would allow us to reopen the decision.”
September 9 2009
http://www.w3.org/html/wg/tracker/issues/64
![Page 19: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/19.jpg)
WebSockets and HTML5
“Since there was no objection, the resolution has now passed.”
September 23 2009
http://www.w3.org/html/wg/tracker/issues/64
![Page 20: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/20.jpg)
WebSockets protocol
• ports 80 and 443
• HTTP “upgrade” handshake
![Page 21: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/21.jpg)
Browser request
GET /test HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Origin: http://www.pjug.org/test
Host: www.pjug.org
Content-Length: 0
![Page 22: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/22.jpg)
Server response
HTTP/1.1 101 Web Socket Protocol Handshake
Upgrade: WebSocket
Connection: Upgrade
Server: FooServer/1.5
WebSocket-Location: ws://www.pjug.org/test
WebSocket-Origin: http://www.pjug.org/test
Content-Length: 0
Date: Fri, 08 May 2009 07:23:58 GMT
![Page 23: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/23.jpg)
WebSockets programming
• client-side API
• server-side API
![Page 24: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/24.jpg)
WebSocket URLs
• ws://example.com/demo
• wss://example.com/demo
![Page 25: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/25.jpg)
JavaScript example
var socket = new WebSocket('wss://game.pjug.org/updates');
![Page 26: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/26.jpg)
event handlers
• onopen
• onmessage
• onerror
• onclose
![Page 27: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/27.jpg)
Server-side API
• no standard Java API
• Jetty API
• Glassfish (Grizzly) API
• jWebsocket API
![Page 28: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/28.jpg)
![Page 29: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/29.jpg)
![Page 30: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/30.jpg)
GWT + WebSockets
• http://code.google.com/p/gwt-websockets/
• http://code.google.com/p/gwt-websocketrpc/
• http://code.google.com/p/quake2-gwt-port
![Page 31: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/31.jpg)
jQuery
• http://code.google.com/p/jquery-websocket/
• http://code.google.com/p/jquery-graceful-websocket/
![Page 32: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/32.jpg)
Other projects
• Glassfish
• jWebSocket
• JBoss Netty
• Resin
![Page 33: Programming WebSocketspjug.github.io/docs/websockets-pjug-2010-04-20.pdf · WebSockets and HTML5 “At last week's telecon, while discussing ISSUE-64, it was proposed that we declare](https://reader035.fdocuments.us/reader035/viewer/2022080720/5f79b6d71450cd780e0c18b7/html5/thumbnails/33.jpg)
Thank you