A better WebSockets demo
Friday, November 27, 2015 by Dave Winer

After a few weeks' experience with WebSockets in JavaScript, I've put together a better demo that shows how they are used in a real application.

 All the demos I found left out an important part, how to know, from the client, if the server disappeared, and more commonly how to know from the server if the client disappeared. Once you have both these under control you can achieve the promise of WebSockets, with an always-open connection and the server piping data back to the client as soon as it's available. 

Here's the new demo app, client and server:

GitHub: betterWebSocketsDemo.

I plan to use this code in 1999.io, that's why I want a code review. If you know what's going on with WebSockets please have a look and let me know if you see anything wrong, or inefficient. Thanks!!

  • Update: Two changes this morning. One simplifies the startup process, no more text message required to "prime" the server. And the server can now handle multiple simultaneous client connections. Thanks to Dan MacTough for the feedback.