Permalink
Browse files

Initial commit

  • Loading branch information...
rauchg committed Nov 10, 2011
0 parents commit 723f8fdbcc6c26a769f2cf61b116dc5f639e633e
Showing with 422 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +43 −0 README.md
  3. +56 −0 index.html
  4. +9 −0 package.json
  5. +290 −0 public/smoothie.js
  6. +22 −0 server.js
@@ -0,0 +1,2 @@
node_modules
.DS_STORE
@@ -0,0 +1,43 @@
# Socket.IO example: latency tester
![](http://f.cl.ly/items/1Z091c3X1M2o3U2d1S33/Image%202011.11.09%206:07:33%20PM.png)
## How to run
1. Clone
2. Run `npm install`
3. Run `node server`
4. Point your browser to `http://localhost:3000`
By default it measures only `xhr-polling`.
If you want to change the transport/port you can try:
```
LATENCY_PORT=4000 LATENCY_TRANSPORT=websocket
```
## License
(The MIT License)
Copyright (c) 2011 Guillermo Rauch <guillermo@learnboost.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,56 @@
<!doctype html>
<html>
<head>
<title>Socket.IO</title>
<script src="/socket.io/socket.io.js"></script>
<script src="/smoothie.js"></script>
<script>
window.onload = function () {
var chart = new SmoothieChart({ grid: { fillStyle: "#ffffff"}, labels: { fillStyle: "#000" } })
, latency = new TimeSeries()
chart.addTimeSeries(latency, { strokeStyle: 'rgba(69, 183, 244, 1)', fillStyle: 'rgba(255, 255, 255, 1)', lineWidth: 4 });
chart.streamTo(document.getElementById("smoothie"), 500);
var socket = io.connect()
, lastDate
socket.on('connect', function () {
document.getElementById('transport').innerHTML = socket.socket.transport.name;
socket.on('message', function () {
var date = +new Date
, ms = date - lastDate
document.getElementById('l').innerHTML = ms;
latency.append(date, ms);
write();
});
function write() {
setTimeout(function () {
lastDate = new Date
socket.send('ping');
}, 100);
}
write();
});
}
</script>
<style>
h1 {
font: bold 16px Helvetica;
}
em {
background: #fbec94;
-webkit-border-radius: 4px;
font-style: normal;
}
</style>
</head>
<body>
<h1><em id="transport"></em> latency: <span id="l"></span> ms</h1>
<canvas id="smoothie">
</body>
</html>
@@ -0,0 +1,9 @@
{
"name": "latency-io"
, "description": "Latency tester for socket.io transports"
, "version": "0.0.1"
, "dependencies": {
"express": "2.4.7",
"socket.io": "0.8.5"
}
}
Oops, something went wrong.

0 comments on commit 723f8fd

Please sign in to comment.