Last active
August 29, 2015 14:22
-
-
Save having-fun-coding/287fccd38323f82c6751 to your computer and use it in GitHub Desktop.
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
| <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> |
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'); | |
| 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