background preloader

Comet (programming)

Comet (programming)
Comet is a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it.[1][2] Comet is an umbrella term, encompassing multiple techniques for achieving this interaction. All these methods rely on features included by default in browsers, such as JavaScript, rather than on non-default plugins. The Comet approach differs from the original model of the web, in which a browser requests a complete web page at a time.[3] The use of Comet techniques in web development predates the use of the word Comet as a neologism for the collective techniques. Comet is known by several other names, including Ajax Push,[4][5] Reverse Ajax,[6] Two-way-web,[7] HTTP Streaming,[7] and HTTP server push[8] among others.[9] Even if not yet known by that name, the very first Comet implementations date back to 2000,[18] with the Pushlets, Lightstreamer, and KnowNow projects. Related:  AJAX

JavaScriptMVC Introducing WebSockets: Bringing Sockets to the Web The Problem: Low Latency Client-Server and Server-Client Connections The web has been largely built around the so-called request/response paradigm of HTTP. A client loads up a web page and then nothing happens until the user clicks onto the next page. However, all of these work-arounds share one problem: They carry the overhead of HTTP, which doesn't make them well suited for low latency applications. Introducing WebSocket: Bringing Sockets to the Web The WebSocket specification defines an API establishing "socket" connections between a web browser and a server. Getting Started You open up a WebSocket connection simply by calling the WebSocket constructor: var connection = new WebSocket(' ['soap', 'xmpp']); Notice the ws:. Attaching some event handlers immediately to the connection allows you to know when the connection is opened, received incoming messages, or there is an error. The second argument accepts optional subprotocols. Cross Origin Communication

Push technology General use[edit] Push services are often based on information preferences expressed in advance. This is called a publish/subscribe model. A client "subscribes" to various information "channels" provided by a server; whenever new content is available on one of those channels, the server pushes that information out to the client. Synchronous conferencing and instant messaging are typical examples of push services. Other uses of push-enabled web applications include market data distribution (stock tickers), online chat/messaging systems (webchat), auctions, online betting and gaming, sport results, monitoring consoles, and sensor network monitoring. Examples[edit] HTTP server push[edit] HTTP server push (also known as HTTP streaming) is a mechanism for sending unsolicited (asynchronous) data from a web server to a web browser. Generally the web server does not terminate a connection after response data has been served to a client. Pushlet[edit] Long polling[edit] Flash XMLSocket relays[edit]

Same origin policy This mechanism bears a particular significance for modern web applications that extensively depend on HTTP cookies to maintain authenticated user sessions, as servers act based on the HTTP cookie information to reveal sensitive information or take state-changing actions. A strict separation between content provided by unrelated sites must be maintained on the client side to prevent the loss of data confidentiality or integrity. History[edit] The concept of same-origin policy dates back to Netscape Navigator 2 in 1995. All modern browsers implement some form of the Same-Origin Policy as it is an important security cornerstone.[2] The policies are not required to match an exact specification [3] but are often extended to define roughly compatible security boundaries for other web technologies, such as Microsoft Silverlight, Adobe Flash, or Adobe Acrobat, or for mechanisms other than direct DOM manipulation, such as XMLHttpRequest. Origin determination rules[edit] JSONP[edit] Workarounds[edit]

How to write a Long Polling Event Push Server with node.js – go-left Software Quick jumps: The API – Installing node – The Skeleton – POSTing Events – GETting Events – Pausing and Resuming Requests – Final Disclaimer For one of my JavaScript projects I’ve needed a push technology to push server events to my web clients. After looking at several options I’ve decided to write a long polling server with node.js. The sample code is available on gist.github git clone The long polling server performs only the task of pushing server events to the client. To make the server more useful we assume that a user can connect simultaneously with multiple browsers and an event pushed for that user is pushed to all browsers the user is currently using (one producer, many consumers). We further want the client/server communication to be robust therefore we don’t know anything about the state of the client and leave it up to the client to request the events it wants to see. The timestamp is also used by the server to expire events that are too old.

WebSocket WebSocket is a protocol providing full-duplex communications channels over a single TCP connection. The WebSocket protocol was standardized by the IETF as RFC 6455 in 2011, and the WebSocket API in Web IDL is being standardized by the W3C. Technical overview[edit] Browser implementation[edit] WebSocket protocol handshake[edit] To establish a WebSocket connection, the client sends a WebSocket handshake request, for which the server returns a WebSocket handshake response, as shown in the following example:[9]:section 1.2 Client request: GET /chat HTTP/1.1 Host: Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw== Sec-WebSocket-Protocol: chat, superchat Sec-WebSocket-Version: 13 Origin: Server response: HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk= Sec-WebSocket-Protocol: chat Note that each line ends with an EOL (end of line) sequence, \r\n.

Asynchronous XMLHttpRequests with XhrIo - Closure Tools Overview JavaScript's XMLHttpRequest enables the responsive, persistent user interfaces that characterize AJAX applications. Web applications can use XMLHttpRequest to communicate with the server from JavaScript without reloading the page or blocking. But while most modern browsers support XMLHttpRequest, different browsers have different implementations. You can smooth over these browser differences by using the Closure Library's XhrIo class. This document first introduces XhrIo with a quick example, then describes in greater detail the process of sending a query, monitoring its status, and processing its results. Quick Examples There are two ways to send an asynchronous request with XhrIo: by calling the the utility function, and by instantiating and calling the instance's send() method. send() Utility Function Example The Closure Library provides a simple utility function for the common use case of one-off requests. [ xhr-quick.js ] [ xhr-quick2.js ]

WebSockets is cool, but what can you do today? | Clay Lenhart’s Blog WebSockets is a new feature that appears to be a great way to send messages from the server to the browser, however today there isn’t much support, both in browsers and on the server in IIS and ASP.Net. Today you can use a Comet technique (in particular, Ajax with long polling ) which is available in all browsers. Using this concept, the browser makes a standard AJAX call to the server that waits until it receives a message. Asynchronous Pages and Asynchronous Controller allow you to have long running HTTP requests without using precious ASP.Net threads. On the server, there are two resource limits to consider with IIS and ASP.Net: HTTP request limits — in IIS7 the default limit is 5000 ASP.Net thread limits — in IIS7 the default limit is 12 x number of CPUs For a typical ASP.Net application (and ASP.Net MVC application), an HTTP request always uses an ASP.Net thread. Take for example an email web application that has jQuery code to check for new mail. $( function () { checkEmail(); } else {