Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<meta charset="utf-8">
<form id="chat">
<fieldset id="blabla">
nickname: <input type="text" name="nickname" value="anonymous" />
message: <input type="text" name="line" value="" />
<button type="submit">Send</button>
<script src="//"></script>
<script src="/"></script>
var socket = io.connect();
// message sending
$('#chat').submit(function (e) {
var message = $('input[name="line"]')
, nickname = $('input[name="nickname"]');
if (!message.val().length) return;
socket.emit('chat', { nickname: nickname.val(), line: message.val() });
// chat messages
socket.on('chat', function (data) {
// escape html
function esc (html) { return new Option(html).innerHTML }
$('<p><strong>' + esc(data.nickname) + ':</strong> ' + esc(data.line) + '</p>')
var connect = require('connect')
, app = connect.createServer(connect.static(__dirname));
// require the new redis store
var RedisStore = require('./')
, io = require('').listen(app);
// configure
io.set('transports', ['xhr-polling', 'jsonp-polling']);
io.set('store', new RedisStore);
// same shit different server
io.sockets.on('connection', function (socket) {
socket.on('chat', function (data) {
console.log('zing, ping pong boom');
socket.broadcast.emit('chat', data);
app.listen(process.env.CLUSTER_PORT || 8080);
console.log('Listening on', app.address())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment