Bergmans Mechatronics LLC HTML5 WebSocket - Enabling Technology for D i W bA li i Dynamic Web Applications John Bergmans Bergmans Mechatronics LLC www.bergmans.com HTML5 & CSS3 User Group LA Los Angeles, CA Jan 26 2011 1616 Bedford Lane, Unit A Phone: 714-474-8956 Newport Beach, CA 92660 Fax: 949-646-1429
32
Embed
WebSocket - Enabling Technology for Dynamic Web Applications
WebSocket is a standardized interface for continuous, bi-directional and low-overhead communication between Web browser clients and back-end servers.
This presentation provides an overview of the WebSocket interface and descriptions of four WebSocket demonstration applications: i) a multi-user Facebook game; ii) a cloud server monitor; iii) a browser-based interface to LabVIEW; and iv) an interface to a MySQL database.
Presented Jan 26, 2011 at the HTML5 & CSS3 LA User Group Meetup, Los Angeles, CA
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
B e r g m a n s M e c h a t r o n i c s L L C
HTML5 WebSocket - Enabling Technology for D i W b A li iDynamic Web Applications
John BergmansBergmans Mechatronics LLC
www.bergmans.com
HTML5 & CSS3 User Group LA Los Angeles, CA
Jan 26 2011
1616 Bedford Lane, Unit A Phone: 714-474-8956Newport Beach, CA 92660 Fax: 949-646-1429
Bergmans Mechatronics LLC
Speaker Intro• Operating Bergmans Mechatronics since 2003• Real-time Web App researcher• Developer of data acquisition and control systems, using LabVIEW and C
Rocket Motor Data Acquisition and Control Systems
ElectromagnetSteel BallLasIR
NH3 M it
Laptop Ethernet Router
g
IR LED Port
NH3 Monitor
Laser Alignment SystemProcessingUnit
Laser-Based Control System Technology
IR LED Port
Photodiode Detector Port
Laser Alignment
Processing Unit
Laser-Based Instrumentation
Control System TechnologyDemonstrator
Laser AlignmentSystem
Bergmans Mechatronics LLC
Generalized Technology Trends
Distributed mainframes
dumb terminals commodity servers
d kt l t bil
Time
desktops laptops mobile
‘80s – ’90s‘60s – ’70s today Time
Standalone
workstations, desktops
y
CommunicationsS d DSL / cable
Fiber toHome
(2+ Gbit/sec)
Phone modem0 300 – 56 kbit/sec
Speed DSL / cable (~10 Mbit/sec)
(2+ Gbit/sec)
Note: SATA 2 0 = 2 4 Gbit/s0.300 – 56 kbit/sec Note: SATA 2.0 = 2.4 Gbit/s
System Developerem-websocket Ilya Grigorik of PostRank with other
contributorsjWebSocket jWebSocket.orgJ tt W bS k t S J ttJetty WebSocket Server JettyKaazing WebSocket Gateway Kaazing Corppywebsocket pywebsocket opensource projectPusher (based on em-websocket) New BambooR i C h T h l I
• Kaazing Corp., Mountain View, CA (www.kaazing.com)
Resin Caucho Technology Inc.
g p , , ( g )• Developer of commercial WebSocket gateway• Emulation for legacy and mobile browsers• User authorization• Secure WebSockets • Contributor to HTML5 spec• Disclosure: BML has referral agreement with and is contractor to
Kaazing
Bergmans Mechatronics LLC
EarthControl – Multiplayer Facebook Game
http://apps.facebook.com/earthcontrol
Bergmans Mechatronics LLC
Browser – Server Architecture for EarthControl Application
Game InstanceI iti li tiLinux Server Initialization
Bergmans Mechatronics LLC
Performance• Typical server transmit rate to each browser:
char string approximately 340 character in length at about 10 Hz ≈ 3400 bytes/sec
• Latency between user input and display update: <~100 ms.
• Kaazing’s WebSocket Emulation enables WebSocket capability on current non-HTML5 bbrowsers
• EarthControl functions well using these browsers• Google Chrome (version 2.0 or later) g ( )• Safari (version 4.0 or later)• Firefox (version 3.0 or later)• Internet Explorer (version 7.0 or later)
Bergmans Mechatronics LLC
Browser - Server Interfacing (Steady State)Facebook iFrame
iFrame
EarthControl_client.html
E thC t l hfunction setup() EarthControl.php(instance YY)
• Plots “top” output in HTML5 <canvas> element• Plots top output in HTML5 <canvas> element• Idea for future work:
• Monitor and control of multiple servers
D t t f
Browser onDesktop or
Mobile Device Data transfer via
WebSocket
WebSocket Message
Mobile Device
MonitorGateway Broker
Server
Agent
Bergmans Mechatronics LLC
Cloud Server Monitor
Bergmans Mechatronics LLC
Remote Access to LabVIEW Application• Goal: monitor and control a LabVIEW application using a plug-in-free browser
LabVIEW Application Browser on
Laptop, Desktop or
Mobile DeviceDesktop / Embedded Device
• Potential Use-Cases
• Monitor and control a LabVIEW-controlled lab test from the desktop in office or on the road using a mobile device
• Monitor large-scale LabVIEW application by crews in the field – ie oil rig i t it iequipment monitoring
• For low-cost embedded systems – eliminate physical UI by using browser to interface to deviceinterface to device
Bergmans Mechatronics LLC
“LabSocket” = LabVIEW + WebSocket
LabSocket system uses WebSockets to enable automatic replication of LabVIEW front panel in a browser without plug-ins
WebSocketG t
MessageB k
LabSocketI t f
Data transfer via
WebSocket
Data transfer via
TCP/IP Socket
LabVIEW Application
GatewayBrokerInterface
Browser onDesktop or
Mobile Device
Server
Mobile DeviceDesktop / Embedded Device
Bergmans Mechatronics LLC
“LabSocket” = LabVIEW + WebSocket
LabSocket system uses WebSockets to enable automatic replication of LabVIEW front panel in a browser without plug-ins
WebSocketG t
MessageB k
LabSocketI t f
Data transfer via
WebSocket
Data transfer via
TCP/IP Socket
LabVIEW Application
GatewayBrokerInterface
Browser onDesktop or
Mobile Device
Server
Mobile DeviceDesktop / Embedded Device
LabSocket Interface
Startup- Establish TCP/IP socket connection to message brokerEstablish TCP/IP socket connection to message broker- LabVIEW Front Panel Screen Scrape, send JavaScript code to web server
Steady-state- Transmit updates in LabVIEW front panel to browser
U d L bVIEW f l b d d i b- Update LabVIEW front panel based on events generated in browser
WebSocket as Alternative to HTTP Request-Response• Initial investigation into use of WebSocket to improve performance of HTTP-
based phpMyAdmin
Bergmans Mechatronics LLC
WebSocket as Potential Alternative to HTTP Request-Response
phpMyAdmin – Popular MySQL Interface
“Navigation” Frame “Content” Frame
Hyperlink in HTML code for this single GUI element
Bergmans Mechatronics LLC
phpMyAdmin – How It Works
Browser Server
1. User clicks on hyperlink in GUI
2. JavaScript creates htt thttp request
http request for updated frame:http://sql.php?db=...&table=...&sql_query=...&token=...
3. Confirm that this is an authentic request
4. Process MySQL query5. Generate new Content
frame with http requests in hyperlinks ffor each active element (including all MySQL queries)
6. Send new html code f f b
html code for new frame which includes for every GUI element:http://sql.php?db=...&table=...&sql_query=...&token=...
for frame to browser7. Render pagep q p p q _q y
Bergmans Mechatronics LLC
WebSocket-MyAdmin – Simplified WebSocket-based MySQL Interface• Objective: To illustrate performance improvements available by using WebSocket
HTML for this element
Event handlers are programmatically assigned to each active GUI element in client-side JavaScript. eg. Columns heading event handlers are assigned using:
If “col1” is pressed client sends to server via WebSocket: “col_heading,col1”