HTML and CSS Reference
In-Depth Information
Creating a new WebSocket is easy and very much like creating
a new Web Worker. The protocol of the URL must be ws:// but
the rest of the URL can be structured just as you would a normal
URL, to be:
var socket = new WebSocket('ws://
¬ 8080/');
For this example, I'm going to be listening only to the messages
that come from the tweets URL. Each is a new tweet from
Twitter that my server has been set up to listen for ( Figure 11.1 ).
FIguRE 11.1 A streaming
connection showing tweets that
my server was listening for.
The messages from the server are being delivered as JSON
messages, forwarded on from Twitter's streaming API. So when
they come in, I'll convert the JSON to data and render the tweet
on the screen:
Search WWH ::

Custom Search