Scott Mattocks

Author
+ Follow
since Mar 26, 2013
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
5
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Scott Mattocks

I am not aware of any well defined lists, but a quick github search shows a bunch of WebSocket libraries.
It really varies on a per implementation basis. Socket.io (the Node.js module for WebSockets) provides both the client and server libraries to make getting an application up and running pretty easy. However, it binds you to certain things like using JSON as your message structure. For certain applications the additional data needed to structure data as JSON can be too expensive. If you were creating a game, which typically involves lots of messages, you would want to send data in as light a wrapper as you can.

There are lots of client side libraries out there as well that will help to make the structuring of messages a bit easier when such a library isn't provided by your backend server.
WebSockets are great for games. They allow you to communicate asynchronously with the server and reduce the communications overhead. You are not limited to games though. Any application which needs to send several small pieces of information to the server can benefit from WebSockets. Also, applications that expect to receive information from the server without needing to prompt the server first are great uses of WebSockets.

Streaming of data from sporting events is a great example use case for WebSockets. In a baseball game, there are periods of activity (pitch, hit, throw) follow by periods of inactivity (warm up between innings, signals between pitches, etc). With AJAX polling, you make a lot of calls and get no updates back. Occasionally, one of the calls returns some information. That information is only timely if your polling interval is small enough. Reducing the interval, increases the number of empty responses. Using WebSockets, the server sends data to the client as it happens without the client needing to poll for information. WebSockets reduce overhead and improve application performance in this example.
Hi Christian,

On the server side, you need something that can negotiate the WebSocket handshake, handle the incoming data and frame the outgoing data properly. There are several implementations available in various languages (http://en.wikipedia.org/wiki/WebSocket#Server_side), but the most popular these days is Socket.io. Socket.io also provides a client side library and several fallback mechanisms. No matter which backend you go with, the logic of the application is still up to you. You have to figure out what data you want to pass and what you are going to do with it.

My book doesn't talk about specific server implementations. It focuses on the JavaScript API on the client side and the protocol itself.

Scott
Are there no new technologies available with HTML5 that isolate the run time environment or help make it easier to filter unwanted characters out of data?
If I were to build a game in HTML5 that uses WebSockets for communication, how can I secure the communications and make sure that one player doesn't inject stuff into the other users' games?
Lets say I were building a solitaire game for the web. What advantages are there in building the UI with canvas over using CSS and JavaScript?