-
-
Save studioijeoma/dc343d584fecb3005fdb to your computer and use it in GitHub Desktop.
This file contains 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
//app.js | |
var io = require('socket.io').listen(process.env.PORT || 1337); | |
io.sockets.on('connection', function(socket) { | |
socket.on('hello', function(data) { | |
socket.broadcast.emit('goodbye', { | |
goodbye : 'goodbye' | |
}); | |
}); | |
}); | |
//hello.html | |
<script src="http://localhost:1337/socket.io/socket.io.js"></script> | |
<script type="text/javascript"> | |
var socket = io.connect('http://localhost:1337'); | |
socket.on('connect', function() { | |
socket.emit('hello', { | |
hello : 'hello' | |
}); | |
}); | |
</script> | |
//goodbye.html | |
<script src="http://localhost:1337/socket.io/socket.io.js"></script> | |
<script type="text/javascript"> | |
var socket = io.connect('http://localhost:1337'); | |
socket.on('goodbye', function(data) { | |
console.log(data.goodbye); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment