Permalink
Browse files

migrated to socket.io 7

  • Loading branch information...
1 parent 2f3aea7 commit e9834540305913d915521c51cb2d5d9dc17f1bb4 @gflarity gflarity committed Aug 21, 2011
Showing with 9 additions and 9 deletions.
  1. +5 −4 heat_tracer.js
  2. +1 −1 public/heat_tracer.html
  3. +3 −4 public/heat_tracer_client.js
View
@@ -1,6 +1,5 @@
var http = require('http');
var libdtrace = require('libdtrace');
-var io = require('socket.io');
var express = require('express');
/* create our express server and prepare to serve javascript files in ./public
@@ -10,6 +9,8 @@ app.configure(function(){
app.use(express.static(__dirname + '/public'));
});
+var io = require('socket.io').listen(app);
+
/* Before we go any further we must realize that each time a user connects we're going to want to
them send them dtrace aggregation every second. We can do so using 'setInterval', but we must
@@ -22,11 +23,10 @@ var dtp_by_session_id = {};
/* In order to effecienctly send packets we're going to use the Socket.IO library which seemlessly
integrates with express.
*/
-var websocket_server = io.listen(app);
/* Now that we have a web socket server, we need to create a handler for connection events. These
events represet a client connecting to our server */
-websocket_server.on('connection', function(socket) {
+io.sockets.on('connection', function(socket) {
/* Like the web server object, we must also define handlers for various socket events that
will happen during the lifetime of the connection. These will define how we interact with
@@ -44,6 +44,7 @@ websocket_server.on('connection', function(socket) {
dtp.go();
dtp_by_session_id[socket.sessionId] = dtp;
+
/* All that's left to do is send the aggration data from the dscript. */
interval_id_by_session_id[socket.sessionId] = setInterval(function () {
var aggdata = {};
@@ -56,7 +57,7 @@ websocket_server.on('connection', function(socket) {
aggdata[key] = val;
}
} );
- socket.send( aggdata );
+ socket.emit( 'message', aggdata );
} catch( err ) {
console.log(err);
}
@@ -1,6 +1,6 @@
<html>
<head>
-<script src="socket.io/socket.io.js"></script>
+<script src="socket.io/socket.io.js"></script>
<script src="heat_tracer_client.js"></script>
</head>
<body onLoad='heat_tracer()'>
@@ -5,20 +5,19 @@ function heat_tracer() {
//Global vars
setup();
- var socket = new io.Socket(); //connect to localhost presently
- socket.connect();
+ var socket = new io.connect(); //connect to localhost presently
socket.on('connect', function(){
console.log('on connection');
var dscript = "syscall:::entry\n{\nself->syscall_entry_ts[probefunc] = vtimestamp;\n}\nsyscall:::return\n/self->syscall_entry_ts[probefunc]/\n{\n\n@time[probefunc] = lquantize((vtimestamp - self->syscall_entry_ts[probefunc] ) / 1000, 0, 63, 2);\nself->syscall_entry_ts[probefunc] = 0;\n}";
- socket.send( { 'dscript' : dscript } );
+ socket.emit( 'message', { 'dscript' : dscript } );
});
/* The only messages we recieve should contain contain the dtrace aggregation data we requested
on connection. */
socket.on('message', function(message){
- //console.log( message );
+ console.log( message );
draw(message);
/* for ( key in message ) {

0 comments on commit e983454

Please sign in to comment.