Skip to content

Instantly share code, notes, and snippets.

@having-fun-coding
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save having-fun-coding/287fccd38323f82c6751 to your computer and use it in GitHub Desktop.

Select an option

Save having-fun-coding/287fccd38323f82c6751 to your computer and use it in GitHub Desktop.
<script src="/socket.io/socket.io.js"></script>
<script>
var server = io.connect('http://localhost:8080');
server.on('question', function(question) {
insertQuestion(question);
});
server.on('answer', function(question, answer) {
answerQuestion(question, answer);
});
</script>
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
io.sockets.on('connection', function(client) {
console.log("Client connected...");
client.on('answer', function(question,answer){
client.broadcast.emit('answer', question, answer);
});
client.on('question', function(question) {
if(!client.question_asked) {
client.question_asked = true;
client.broadcast.emit('question', question);
}
});
});
server.listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment