WebSockets: TCP in Javascript

Slides:



Advertisements
Similar presentations
A Javascript Implementation of the Binary DIS Protocol Don McGregor, Don Brutzman, Curt Blais, MOVES Institute
Advertisements

Java Script Session1 INTRODUCTION.
Ajax / Rich Internet Applications ICW Lecture 21 Errol Thompson.
Reverse AJAX and HTML5 Based Clients for Embedded Control and Monitoring Systems C Robson, C Bohm, Stockholm University or "HTML5, why should we care?"
Quick Tour of the Web Technologies: The BIG picture LECTURE A bird’s eye view of the different web technologies that we shall explore and study.
Web server and web browser It’s a take and give policy in between client and server through HTTP(Hyper Text Transport Protocol) Server takes a request.
Computer Concepts 2014 Chapter 7 The Web and .
Lightning Talk Fred Rodriguez Aakash Juneja CPSC 473 March 16, 2012.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
JavaScript & jQuery the missing manual Chapter 11
ASP.NET + Ajax Jesper Tørresø ITNET2 F08. Ajax Ajax (Asynchronous JavaScript and XML) A group of interrelated web development techniques used for creating.
Orbited Scaling Bi-directional web applications A presentation by Michael Carter
CS 241 Section (04/19/12). MP8  Web Server  Due: Tuesday, May 1 st, 11:59pm  What will you be doing?  Creating a web-server in C that serves HTML.
1 Geospatial and Business Intelligence Jean-Sébastien Turcotte Executive VP San Francisco - April 2007 Streamlining web mapping applications.
WebSocket Gateway Don McGregor Research Associate MOVES Institute
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
WebRTC Don McGregor Research Associate MOVES Institute
Simulation Networking Standards and the Web Don McGregor Research Associate MOVES Institute
Chapter 1 Getting Started with ASP.NET Objectives Why ASP? To get familiar with our IDE (Integrated Development Environment ), Visual Studio. Understand.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
4.01 How Web Pages Work.
Research of Web Real-Time Communication Based on WebSocket
PhoneGap, Processing.
Progress Apama Fundamentals
JQuery Fundamentals Introduction Tutorial Videos
Web Programming Language
4.01 How Web Pages Work.
File Management in the Cloud
AJAX and JSON Day 8.
Selenium and Selenium on Rails
CSE 154 Lecture 11: AJAx.
ITM352 PHP and Dynamic Web Pages: Server Side Processing 1.
Web Concepts Lesson 2 ITBS2203 E-Commerce for IT.
WWW and HTTP King Fahd University of Petroleum & Minerals
CS5220 Advanced Topics in Web Programming Introduction to WebSocket
ASP.NET SignalR SoftUni Team C# MVC Frameworks Technical Trainers
Chapter 1 Introduction to Computers, Programs, and Java
Google Web Toolkit Tutorial
Data Virtualization Tutorial… CORS and CIS
Simulation as a Service, Scalability, and Network Architectures
Tracking and Booking Taxi
BTEC NCF Dip in Comp - Unit 15 Website Development Lesson 05 – Website Performance Mr C Johnston.
Application with Cross-Platform GUI
AJAX.
Asynchronous Java script And XML Technology
Web Caching? Web Caching:.
Form Validation and AJAX
AJAX.
PHP / MySQL Introduction
Module 3 Building a web app.
Building real-time web apps with WebSockets using IIS, ASP.NET and WCF
WebSocket: Full-Duplex Solution for the Web
PROJECT ON WEB DESIGNING BY – POOJA SINGH CSE. WEB DESIGNING Web design Web design is a similar process of creation, with the intention of presenting.
CSE 154 Lecture 11: AJAx.
Building real-time web apps with HTML5 WebSockets
CSE 154 Lecture 22: AJAX.
Get Enterprise-Grade Call Handling and Control for Microsoft Office 365 and Skype for Business with the Bridge Boss-Admin Executive Console OFFICE 365.
Lecture 1: Multi-tier Architecture Overview
Introduction to HTML5 and WebSockets.
JavaScript & jQuery AJAX.
Secure Web Programming
How to Improve Releasing Efficiency via i18N/L10n Test Automation.
Chengyu Sun California State University, Los Angeles
Lecture 12: The Fetch Api and AJAx
4.01 How Web Pages Work.
New Tools In Education Minjun Wang
Introduction to JavaScript
WCF Data Services and Silverlight
Running C# in the browser
Communicating via WebSockets
Presentation transcript:

WebSockets: TCP in Javascript Don McGregor Research Associate MOVES Institute Understanding global peace and conflict means understanding of human communities in the midst of and in response to change. US Joint Forces Command noted that “changes in the strategic landscape… new technologies, and the adaptation and creativity of our adversaries will alter….operations a great deal. Here too, the past can suggest much about the future – the nature of change, its impacts on human societies….” This presentation provides an overview of the project and research methodology, progress to date and planned go-forward efforts. 2008. The Joint Operating Environment, United States Joint Forces Command Center for Joint Futures (J59). mcgredo@nps.edu

Websockets The problem: web pages were originally designed to be static and loaded once from the web server Ask for an HTML file; receive it from the server; render the HTML in the web browser State of the art for 1998 This doesn’t work well for highly interactive web pages. What if you’re using a web mail program, and new mail comes in? The only choice is to constantly hit the reload button

Interactive Web Applications For a mail application we want live buttons and menus, updates to the display when new mail comes in, and other bling.

Economics of Web Apps Write Javascript once, run mostly everywhere Sort of. There are browser specific things, version issues, and so on. Welcome to the real world. Mobile devices for “free”: tablets, phones Simplified host deployment Simplified upgrades, configuration management Much faster product upgrade cycles Deploy server side on cloud (private or public) How many web apps do you use a day, vs how many installed desktop apps? Facebook, webmail, calendaring, phone books, games Still mostly use Office on desktop (though, Google Docs), and very complex apps Maybe not Call of Duty yet, but maps, simple virtual (WebGL), constructive, etc.

Javascript Javascript is a programming language that can run in a web browser page. It can add interactivity (buttons, menus) but is also a general programming language Vendors are in an arms race for faster Javascript engines because of all the webapps using js

Websockets We also want to receive updates from the server relevant to our application. (What data?) There have been an enormous number of kludges to get around the basic design fact of web pages that are loaded from the server once AJAX, Comet, long polling, … They work, but they have long latency (on the order of a second or more) and are fairly complex What’s “polling?” Why not just have a javascript way to open a TCP socket to the server?

Websockets Javascript in the web page establishes a connection to the web server, requests that a TCP socket be opened After the connection is established, send & receive over the always-open socket W3C handles the standard for the API, IETF for the underlying protocol negotiation Avoid polling and resulting long latency

Websockets Details: the web page starts out establishing a TCP socket to the web server to send HTTP The web server recognizes the client is requesting an upgrade to a websocket, and repurposes it. Afterwards it’s used as a websocket This means we need a server that recognizes this upgrade request. I’ve provided that for you But in the end, it’s a TCP socket that can be seen with “netstat –an”

Architecture IE Page Firefox Page Safari Mobile Page Websocket (full duplex, bidirectional TCP socket with Javascript API) Web Server & Websocket Server

Architecture A web page loads and then executes some javascript. The javascript opens a TCP socket to the server. The page sends a message to the server, and the server repeats it to the other pages The page receives the message and does something with it, such as update an entity location

Networked Virtual Environments We also have WebGL, which you’ve seen in the graphics class We have a programming language, 3D, and networking, so we can create a networked virtual environment entirely inside a web page Can also use Google Maps, OpenStreetMap, Javascript 2D, mashup with other web applications, ….

Javascript Javascript (in the web page): create a Websocket object, point it at the server, override the relevant methods var websocket; if(window.WebSocket) websocket = new WebSocket(SERVER_URL); else if (Window.MozWebSocket) websocket = new MozWebSocket(SERVER_URL); else alert(“This web browser does not support web sockets”); // Attach functions to the the web socket for various events websocket.onopen = function(evt){console.log("websocket onopen");}; websocket.onclose = function(evt){console.log("websocket close")}; websocket.onerror = function(evt){console.log("websocket error")}; websocket.onconnect = function(evt){console.log("websocket connect");}; websocket.onmessage = function(evt){console.log("Websocket message from server:", evt)};

Javascript In what format should we send messages? JSON works, easy to use, not necessarily easy to be interoperable Standardized binary messages can be sent, such as DIS (more on this later) It’s entirely plausible to make up your own ad hoc protocol for class work and network any 3D scene you did in the graphics class

Server Side How do we get this to work on the server side? We need a web server that can accept websocket requests (much like the ServerSocket in Java) and that can serve content Provided for you. Java program that uses Jetty, a Java-based web server framework See https://github.com/mcgredonps/JSONWebsocketRepeater Open project in Netbeans, run. It starts a web server on port 8282, serves files from the “content” directory

JSON Repeater Open Javascript Console to see output index.html file in contents directory

Code Note one section of code var SERVER_WEBSOCKET_URL = “ws://localhost:8282” websocket = new WebSocket(SERVER_WEBSOCKET_URL); What does “localhost” refer to? What happens when the HTML page is downloaded to your host and run? What host does it try to connect to?

Code: Async websocket = new WebSocket(URL); and then calling send() in the next line will probably fail After creation the websocket takes some time to finish creation. It’s not a finished object until the onconnect function fires. You should probably use something like window.setInterval(myFunction, timeInMs); to try to send after some period of time

Server The server is straightforward: Accept connections from clients, maintain list of connections Relay messages between clients Act as a web server for html, javascript, image files Potentially it can do a lot more, such as filtering on the server side

What Format for Messages? Text is a good format for sending things back and forth. What should the text look like? JSON is a popular format that makes it easy to convert from a text string to a Javascript object

Javascript Object var anObject = new Object(); // or = {} anObject.myProperty = “This is my property” anObject.value=17; Created a Javascript object with two properties. We can convert the js object to a string with var jsonString = JSON.stringify(anObject); And get back ‘{“myProperty”:”This is my property”, “value”:17}’ And use this value to send across a websocket. Likewise we can convert It back to a js object with var myJSObject = JSON.parse(jsonString);

Summary We can do a close analog of TCP sockets in Javascript, using a hub-and-spoke architecture This has significant implications for DoD M&S Mobile devices Simplified configuration control Integration with other web applications Still some problems. The technology is there, the implementation is not