Created
February 4, 2013 20:05
-
-
Save drinchev/4709257 to your computer and use it in GitHub Desktop.
Basic socket.io + express app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'), | |
app = express(), | |
http = require('http'), | |
server = http.createServer(app), | |
io = require('socket.io').listen(server); | |
app.get('/', function(req, res) { | |
res.send('<!doctype html> \ | |
<html> \ | |
<head><meta charset="utf-8"></head> \ | |
<body> \ | |
<center>Welcome to <strong>socket.io</strong></center> \ | |
<script src="/socket.io/socket.io.js"></script> \ | |
<script> \ | |
var socket = io.connect(); \ | |
socket.emit("message", "Howdy"); \ | |
setInterval(function () { \ | |
socket.emit("message", "Ping"); \ | |
}, 1000); \ | |
</script> \ | |
</body> \ | |
</html>'); | |
}); | |
io.sockets.on('connection', function (socket) { | |
socket.on('message', function(msg) { | |
console.log(msg); | |
}); | |
}); | |
server.listen(8000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment