Skip to content

Commit

Permalink
configurable server poll timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Windal committed Mar 31, 2013
1 parent f6c006f commit a976cc5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions JScribbleServer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@

var _ = require('underscore');

var socket = null;
var io;
module.exports = {
start: function(port) {
var io = require('socket.io').listen(port);

start: function(port, timeout) {
io = require('socket.io').listen(port);
io.set('close timeout', timeout);
io.set('client store expiration', timeout);

var messages = [];

Expand All @@ -15,8 +19,8 @@ module.exports = {
io.set("polling duration", 10);
});

io.sockets.on('connection', function (socket) { // handler for incoming connections

io.sockets.on('connection', function (sock) { // handler for incoming connections
socket = sock;
socket.on('chat', function (data) {
var msg = JSON.parse(data);
msg.time = new Date();
Expand Down Expand Up @@ -62,11 +66,19 @@ module.exports = {
});

socket.on('close', function(data) {
var msg= JSON.parse(data);
var msg = JSON.parse(data);
socket.disconnect();
});
});
}
};
});
},
stop: function() {
console.log("stoping server");
if (socket) {
socket.disconnect();
io.server.close();
}
socket = null;
}
};


2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ app.listen(port, function() {
app.get('/', routes.index);

var server = require('./JScribbleServer');
server.start(app);
server.start(app, 5);

0 comments on commit a976cc5

Please sign in to comment.