Last active
August 29, 2015 13:57
-
-
Save mi-ca/9462664 to your computer and use it in GitHub Desktop.
socket.io server.js source
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
var socket = io.connect('http://localhost:8080'); // changement du port | |
// quand tu reçois news | |
socket.on('news', function (data) { | |
console.log(data); // afficher les data reçues par le server | |
socket.emit('my other event', { my: 'data' }); // émet un nouvel évent | |
}); | |
socket.on('world',function(data){ | |
console.log(data); | |
}); | |
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
var io = require('socket.io').listen(8080); // changement du port en 8080 | |
// lors de la connexion | |
io.sockets.on('connection', function (socket) { | |
socket.emit('news', { hello: 'world' }); // envoi l'event news | |
socket.on('my other event', function (data) { // quand tu reçois "my other event" | |
console.log(data); // console log les dota reçu par le client | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment