Skip to content

Instantly share code, notes, and snippets.

@mi-ca
Last active August 29, 2015 13:57
Show Gist options
  • Save mi-ca/9462664 to your computer and use it in GitHub Desktop.
Save mi-ca/9462664 to your computer and use it in GitHub Desktop.
socket.io server.js source
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);
});
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