Permalink
Browse files

After 5 seconds, send a message to the first two users, with customis…

…ed text
  • Loading branch information...
mheap committed Mar 4, 2013
1 parent 61151cb commit 0d299e2db6f9c5ef247bb73611a184b82aacd345
Showing with 14 additions and 7 deletions.
  1. +9 −4 app.js
  2. +5 −3 index.html
13 app.js
@@ -4,6 +4,8 @@ var app = require('http').createServer(handler)

app.listen(3000);

var clients = [];

function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
@@ -18,8 +20,11 @@ function handler (req, res) {
}

io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
clients.push(socket.id);
});

setTimeout(function(){
io.sockets.socket(clients[0]).emit("greeting", "Howdy, User 1!");
io.sockets.socket(clients[1]).emit("greeting", "Hey there, User 2");
}, 5000);
//
@@ -1,8 +1,10 @@
<div id="content"></div>

<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
socket.on('greeting', function(data){
document.getElementById("content").textContent = data;
});
</script>

0 comments on commit 0d299e2

Please sign in to comment.