Comments on: Methods of communication https://stevefaulkner.github.io/html5doctored/methods-of-communication/ helping you implement HTML5 today Wed, 25 May 2016 22:16:45 +0000 hourly 1 By: Junior https://stevefaulkner.github.io/html5doctored/methods-of-communication/#comment-20607 Wed, 14 Dec 2011 11:02:37 +0000 http://html5doctor.com/?p=2847#comment-20607 Hi all

Someone to know how to do an Audio Streaming between clients with HTML5? (In any browser)

]]>
By: Tom Kersten https://stevefaulkner.github.io/html5doctored/methods-of-communication/#comment-18262 Mon, 31 Oct 2011 03:26:41 +0000 http://html5doctor.com/?p=2847#comment-18262 @cclark: This is an old comment, but to follow up, if you add a listener for the “close” event on the request object, you can do any sort of necessary cleanup.

For example, to close down a redis pub/sub connection when someone closes their window, you can do the following:


req.on("close", function() {
// close down this pub/sub connection when a client
// closes their browser window
pub_sub_client.unsubscribe();
pub_sub_client.quit();
});

]]>
By: CClark https://stevefaulkner.github.io/html5doctored/methods-of-communication/#comment-16168 Tue, 12 Jul 2011 21:49:45 +0000 http://html5doctor.com/?p=2847#comment-16168 I have a question about using server side code (Node.js) and SSE. It seems once you open a response, you will keep trying to post to the response stream even if it has been closed by the client. In the code you posted sseConnections is an array that holds every http response object that is created. Once a browser closes the connection and then starts back up, you will still be sending SSEs to response objects that no longer exist…

Is there any way to determine if a response object is still valid?

So that if you have 100’s of people connecting to your site, you will not keep trying to update them once they have closed the browser?

]]>
By: Remy Sharp https://stevefaulkner.github.io/html5doctored/methods-of-communication/#comment-14716 Mon, 21 Mar 2011 11:13:13 +0000 http://html5doctor.com/?p=2847#comment-14716 @Nicholas – I’ve also written an EventSource polyfill that I’m using in jsconsole.com> for the remote device debugging that’s used on the mobile devices that don’t natively support EventSource – like the Android 2.2 and Palm Pre. Exactly as you described, it defaults down to Ajax based polling: https://github.com/remy/polyfills/blob/master/EventSource.js

It’s not 100% perfect, but it definitely mirrors basic usage of EventSource and gives me the device support I needed.

]]>
By: Nicholas C. Zakas https://stevefaulkner.github.io/html5doctored/methods-of-communication/#comment-14712 Mon, 21 Mar 2011 03:39:21 +0000 http://html5doctor.com/?p=2847#comment-14712 @Ricardo – Web workers are very different than setTimeout(). The setTimeout() function simply tells the browser to wait until later to execute JavaScript – but it does so on the same thread (called the UI thread, the same one responsible for repaints and reflows). Web workers actually execute outside of the UI thread, so they can be executing at the exact same time as code that manipulates the DOM. Keep in mind that Web Workers cannot access the DOM because they don’t execute on the UI thread, so you are limited to passing data into and out of a worker. You may want to check out my presentation about JavaScript performance, which has some info about this: http://www.slideshare.net/nzakas/high-performance-javascript-fronteers-2010

]]>
By: Nicholas C. Zakas https://stevefaulkner.github.io/html5doctored/methods-of-communication/#comment-14711 Mon, 21 Mar 2011 03:35:06 +0000 http://html5doctor.com/?p=2847#comment-14711 Even though Server-Sent Events are only “officially” supported in some browsers, it’s pretty easy to add support in others. In Firefox, for example, you can use progress events on the XHR object to mimic the behavior. Unfortunately, IE will still need to do polling until they support progress events, but it’s very easy to switch to the correct approach on the server. In my YUI EventSource component, I just add a custom header via JavaScript telling the server that the browser only supports polling, which allows you to write server-side code similar to the example posted here: http://yuilibrary.com/gallery/show/eventsource

]]>
By: Sean https://stevefaulkner.github.io/html5doctored/methods-of-communication/#comment-14698 Thu, 17 Mar 2011 13:40:15 +0000 http://html5doctor.com/?p=2847#comment-14698 Thanks for this summary, this is a subject I am sorely lacking in. This is a great jumping point for research.

]]>
By: Ricardo Lucio https://stevefaulkner.github.io/html5doctored/methods-of-communication/#comment-14202 Fri, 11 Feb 2011 12:16:12 +0000 http://html5doctor.com/?p=2847#comment-14202 Regarding the Web Worker, I’m a little more than a newbie in javascript programmer, and I always thought you could reach multi-thread capabilities within javascript with the usage of the setTimeout() function.

Can you please clarify that? What are the benefits of WebWorker (besides the context isolation) over the well-known setTimeout() function?

]]>
By: Phil Leggetter https://stevefaulkner.github.io/html5doctored/methods-of-communication/#comment-13963 Thu, 20 Jan 2011 17:30:43 +0000 http://html5doctor.com/?p=2847#comment-13963 Although Comet was originally defined as a paradigm for Ajax to allow server to client push that definition, along with the technology, has evolved. In Alex Russell’s diagram he lists a “Comet engine” and I believe the technology behind the Comet engine doesn’t have to be JavaScript (in the same way WebSockets isn’t just for Web Browsers).

The same method of connecting to a server and receiving push updates has been used in many client applications using many technologies. In Kwwika for instance, which uses clustered Comet servers under the hood, we have APIs for JavaScript and .NET, Silverlight, ActionScript (Flash), C, Objective-C (iPhone/iPad) and Java. Just because we have these client APIs that connect to our service does this mean that we can’t call our servers Comet servers. IMHO, no!

A good Comet server implementation will hide away the underlying communication protocol. The client API will choose the most appropriate means of communication for the client technology and runtime environment (including network) as well as having a fallback strategy e.g. try HTTP Streaming then HTTP long-polling then, if you really have to, fallback to HTTP classic polling.

The next evolution for Comet servers has been to add support for the WebSocket protocol as one of it’s communication options. The WebSockets protocol is still under development so my preferred choice of communication would probably still be HTTP Streaming as it’s more reliable and is less likely to be interfered with by proxies and firewalls (WebSockets rely on HTTP headers which can easily be mangled. HTTPS connections are a solution).

So, I wouldn’t put it as you have. Instead of:

It’s my opinion that Web Sockets replaces Comet. Comet is a way of hacking the browser to giving us real-time server messages. The Web Sockets API provides that natively.

I would instead say:

WebSockets may replace HTTP Streaming as the preferred method of client/server communication.

If WebSockets gets the support it deserves it will win out. The native bi-directional support is a really big deal and I hope that the protocol becomes rock solid and that the Internet Infrastructure quickly updates to make it suitable for all production environments.

Note: This is a resubmission of my comment on January 18th, 2011 at 7:13 pm since the previous one is still awaiting moderation.

]]>
By: Ian Alderson https://stevefaulkner.github.io/html5doctored/methods-of-communication/#comment-13934 Tue, 18 Jan 2011 22:58:28 +0000 http://html5doctor.com/?p=2847#comment-13934 Hi. Great blog, but I disagree with your opinion that “that Web Sockets replaces Comet”. I believe that Web Sockets are best used within a Comet implementation as the best possible streaming connection technique, rather than as a replacement for Comet. There are various reasons for my belief, but these are the ones that immediately come to mind. In the interests of full disclosure, I work for a company that provides a Comet server, however I believe the following statements are impartial observations of some genuine issues with Web Sockets.

1. There are Web Socket issues with proxy servers. The protocol looks somewhat like http, however it isn’t quite http. It smuggles an 8 byte body to the server during the negotiation stage which is likely to cause massive issues with proxy servers. Web proxies love to interfere with HTTP connections and until they are all updated to understand Web Socket protocol (or, more unlikely, if even possible, the Web Socket protocol is changed so that it conforms to http) this is likely to become a more significant barrier than browser support for Web Sockets. In this scenario a Comet library can failover to a non Web Socket connection type.

2. There is no intrinsic support (at the moment) for heartbeats to keep connection alive. Badly configured firewalls have a wonderful tendency to decide that a connection must be dead if no data has been sent through it for a while, defeating the purpose of a supposed persistent connection. Comet implementations typically already have application level heartbeats to solve this. Obviously a Web Socket implementation can do this too, but you’re starting on a slippery slope of writing more code to get around their deficiencies – surely it would be better to use a library that already does this for you (and covers all the scenarios you haven’t thought of yet).

3. With Web Sockets you need to write your own reconnection logic, potentially including failover to another server if a connection to the original server cannot be established. This is a very real scenario when dealing with the transient network connectivity of mobile devices. Again Comet implementations will typically handle this for you.

Web Sockets are absolutely awesome, providing full duplex connection. However the fact that they are low level means that you need to write a reasonable amount of code to make them reliable within a production environment. Couple this with the fact that they aren’t supported in all browsers, and the most sensible route I can see is to use a library that encapsulates all of this logic for you. if someone decided to write one of these from scratch, rather than using one of the existing Comet libraries, then, for me at least, I would consider it to be a Comet implementation, but one that only happens to use the Web Socket protocol.

]]>