Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'd recommend looking at the project Socket.IO and Socket.IO-node. It uses HTML5 WebSockets if available, and falls back automatically and gracefully (no intervention required) to Flash sockets and XHR-polling as necessary</p> <p>Here's a script to download the files:</p> <pre><code>mkdir socket.io cd socket.io git clone https://github.com/LearnBoost/Socket.IO.git --recursive git clone https://github.com/LearnBoost/Socket.IO-node.git --recursive </code></pre> <p>Here's the server.js file:</p> <pre><code>var http=require('http'); var url=require('url'); var fs=require('fs'); var sys=require('sys'); var io=require('./socket.io/Socket.IO-node'); //adjust path as necessary... var server=http.createServer(function(req,res){ res.writeHead(200,{'Content-Type':'text/html'}); res.write('Hello world'); res.end(); }); server.listen(8000); var socket=io.listen(server); socket.on('connection', function(client){ onConnection(client); client.on('message', function(){ onMessage(); }) client.on('disconnect', function(){ onDisconnect(); }) }); function onConnection(client){ console.log('connection'); //client.connected; //tests if connected //client.send("message"); //client.broadcast("message"); //send to all other conns } function onMessage(){ console.log('message'); } function onDisconnect(){ console.log('disconnect'); } }); </code></pre> <p>Run the above server with <code>sudo node server.js</code></p> <p>And here is your index.html to be run in a browser:</p> <pre><code>&lt;script src="./socket.io/Socket.IO/socket.io.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt; &lt;!--Adjust path as necessary--&gt; &lt;script&gt; var host="localhost"; var port=8000; var socket=new io.Socket(host,{'port':port}); socket.connect(); socket.on('connect',function(){onConnect();}) socket.on('message',function(data){onMessage(data);}) socket.on('disconnect',function(){onDisconnect();}); function onConnect(){ ///alert('connect'); } function onMessage(data){ //alert('message'); } function onDisconnect(){ //alert('disconnect'); socket.connect(); } &lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload